def login_view(request): ''' The view of the login page. ''' ANONYMOUS_SESSION = request.session.get('ANONYMOUS_SESSION', False) page_name = "Login Page" redirect_to = request.GET.get('next', reverse('homepage')) if (request.user.is_authenticated() and not ANONYMOUS_SESSION) or (ANONYMOUS_SESSION and request.user.username != ANONYMOUS_USERNAME): return HttpResponseRedirect(redirect_to) form = LoginForm(request.POST or None) if form.is_valid(): user = form.save() login(request, user) if ANONYMOUS_SESSION: request.session['ANONYMOUS_SESSION'] = True return HttpResponseRedirect(redirect_to) elif request.method == "POST": reset_url = request.build_absolute_uri(reverse('reset_pw')) messages.add_message(request, messages.INFO, MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url)) return render_to_response('login.html', { 'page_name': page_name, 'form': form, 'oauth_providers': _get_oauth_providers(), 'redirect_to': redirect_to, }, context_instance=RequestContext(request))
def login_view(request): """ The view of the login page. """ ANONYMOUS_SESSION = request.session.get("ANONYMOUS_SESSION", False) page_name = "Login Page" redirect_to = request.GET.get("next", reverse("homepage")) if (request.user.is_authenticated() and not ANONYMOUS_SESSION) or ( ANONYMOUS_SESSION and request.user.username != ANONYMOUS_USERNAME ): return HttpResponseRedirect(redirect_to) form = LoginForm(request.POST or None) if form.is_valid(): user = form.save() login(request, user) if ANONYMOUS_SESSION: request.session["ANONYMOUS_SESSION"] = True return HttpResponseRedirect(redirect_to) elif request.method == "POST": reset_url = request.build_absolute_uri(reverse("reset_pw")) messages.add_message(request, messages.INFO, MESSAGES["RESET_MESSAGE"].format(reset_url=reset_url)) return render_to_response( "login.html", {"page_name": page_name, "form": form, "oauth_providers": _get_oauth_providers(), "redirect_to": redirect_to}, context_instance=RequestContext(request), )
def login_view(request): ''' The view of the login page. ''' ANONYMOUS_SESSION = request.session.get('ANONYMOUS_SESSION', False) page_name = "Login Page" redirect_to = request.GET.get('next', reverse('homepage')) if (request.user.is_authenticated() and not ANONYMOUS_SESSION) or ( ANONYMOUS_SESSION and request.user.username != ANONYMOUS_USERNAME): return HttpResponseRedirect(redirect_to) form = LoginForm(request.POST or None) if form.is_valid(): user = form.save() login(request, user) if ANONYMOUS_SESSION: request.session['ANONYMOUS_SESSION'] = True return HttpResponseRedirect(redirect_to) elif request.method == "POST": reset_url = request.build_absolute_uri(reverse('reset_pw')) messages.add_message( request, messages.INFO, MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url)) return render_to_response('login.html', { 'page_name': page_name, 'form': form, 'oauth_providers': _get_oauth_providers(), 'redirect_to': redirect_to, }, context_instance=RequestContext(request))