diff --git a/templates/mailman-django/base.html b/templates/mailman-django/base.html index 3f238e5..3049df8 100644 --- a/templates/mailman-django/base.html +++ b/templates/mailman-django/base.html @@ -45,7 +45,11 @@
diff --git a/urls.py b/urls.py index 8d1a8e4..d3a2bb9 100644 --- a/urls.py +++ b/urls.py @@ -23,7 +23,8 @@ urlpatterns = patterns('mailman_django.views', (r'^$', 'list_index'), - url(r'^accounts/login/$', 'login', name = 'login'), + url(r'^accounts/login/$', 'user_login', name = 'user_login'), + url(r'^accounts/logout/$', 'user_logout', name = 'user_logout'), url(r'^administration/$', 'administration', name = 'administration'), url(r'^domains/$', 'domain_index', name = 'domain_index'), url(r'^domains/new/$', 'domain_new', name = 'domain_new'), diff --git a/views.py b/views.py index 73b6e38..85a8ea8 100644 --- a/views.py +++ b/views.py @@ -514,7 +514,12 @@ 'member': member} ,context_instance=RequestContext(request)) -def login(request,template = 'mailman-django/login.html'): +def user_logout(request): + from django.contrib.auth import logout + logout(request) + return redirect('user_login') + +def user_login(request,template = 'mailman-django/login.html'): """ Let the user logout. Some functions requires the user to be logged in to perform the @@ -531,39 +536,30 @@ """ New Login page used with the RESTBackend, will allow login and logout depending on the current user status. """ - from django.contrib.auth import authenticate + from django.contrib.auth import authenticate, login error = None message = None form=None - - if request.user.is_authenticated(): - message = _("You can end your user session here") - return render_to_response(template, {'form': form, - 'message': message,} - ,context_instance=RequestContext(request)) - else: - if request.POST: - form = Login(request.POST) - if form.is_valid(): - user = authenticate(username=form.cleaned_data["user"], - password=form.cleaned_data["password"]) - if user is not None: - if user.is_active: - if "next" in request.GET.keys(): - return redirect(request.GET["next"]) - else: - return redirect("list_index") + if request.POST: + form = Login(request.POST) + if form.is_valid(): + user = authenticate(username=form.cleaned_data["user"], + password=form.cleaned_data["password"]) + if user is not None: + if user.is_active: + if "next" in request.GET.keys(): + login(request,user) + return redirect(request.GET["next"]) else: - error= _("Your account has been disabled!") + return redirect("list_index") else: - error = _("Your username and password were incorrect.") - else: - form = Login() - message = "You are required to login to continue. Please provide a valid email address and a password." - return render_to_response(template, {'form': form, + error= _("Your account has been disabled!") + else: + error = _("Your username and password were incorrect.") + else: + form = Login() + message = "You are required to login to continue. Please provide a valid email address and a password." + return render_to_response(template, {'form': form, 'error': error, 'message': message,} ,context_instance=RequestContext(request)) - - -