def login(request, template_name): """ Do some pre-checking before handing off to the standard login view. If anything goes wrong just let the standard login handle it. """ if request.user.is_authenticated(): return HttpResponseRedirect(urlresolvers.reverse("default_profile")) try: if request.method == "POST": try: user = User.objects.get(email=request.POST["username"]) except (User.DoesNotExist, User.MultipleObjectsReturned): user = User.objects.get(username=request.POST["username"]) if user.indexer.registration_expires is not None: if date.today() > (user.indexer.registration_expires + timedelta(1)): return render_error( request, ( 'The account with the email "%s" was never confirmed ' 'and has expired. You may <a href="' + urlresolvers.reverse("register") + '">re-register</a>. ' ) % esc(user.email), is_safe=True, ) return render_error( request, ( 'The account with email "%s" has not yet been confirmed. ' "You should receive an email that gives you a URL to visit " "to confirm your account. After you have visited that URL " "you will be able to log in and use your account. Please " '<a href="mailto:%s">contact us</a> if you do not receive ' "the email within a few hours." ) % (esc(user.email), settings.EMAIL_CONTACT), is_safe=True, ) except User.DoesNotExist: pass if "next" in request.POST: next = request.POST["next"] if re.match(r"/accounts/confirm/", next, flags=re.I): post = request.POST.copy() post["next"] = urlresolvers.reverse("welcome") request.POST = post if re.match(r"/gcd-error/", next, flags=re.I): post = request.POST.copy() post["next"] = urlresolvers.reverse("home") request.POST = post return standard_login(request, template_name=template_name, authentication_form=LongUsernameAuthenticationForm)
def login(request, template_name, landing_view='default_profile'): """ Do some pre-checking before handing off to the standard login view. If anything goes wrong just let the standard login handle it. """ if request.user.is_authenticated(): return HttpResponseRedirect(urlresolvers.reverse(landing_view)) try: if request.method == "POST": try: user = User.objects.get(email=request.POST['username']) except (User.DoesNotExist, User.MultipleObjectsReturned): user = User.objects.get(username=request.POST['username']) if user.indexer.registration_expires is not None: if date.today() > (user.indexer.registration_expires + timedelta(1)): return render_error( request, ('The account with the email "%s" was never confirmed ' 'and has expired. You may <a href="' + urlresolvers.reverse('register') + '">re-register</a>. ') % esc(user.email), is_safe=True) return render_error( request, ('The account with email "%s" has not yet been confirmed. ' 'You should receive an email that gives you a URL to visit ' 'to confirm your account. After you have visited that URL ' 'you will be able to log in and use your account. Please ' '<a href="mailto:%s">contact us</a> if you do not receive ' 'the email within a few hours.') % (esc(user.email), settings.EMAIL_CONTACT), is_safe=True) except User.DoesNotExist: pass if 'next' in request.POST: next = request.POST['next'] if re.match(r'/accounts/confirm/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('welcome') request.POST = post if re.match(r'/gcd-error/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('home') request.POST = post return standard_login(request, template_name=template_name, authentication_form=LongUsernameAuthenticationForm)
def login(request, template_name): """ Do some pre-checking before handing off to the standard login view. If anything goes wrong just let the standard login handle it. """ if request.user.is_authenticated(): return HttpResponseRedirect(urlresolvers.reverse('default_profile')) try: if request.method == "POST": user = User.objects.get(username=request.POST['username']) if user.indexer.registration_key is not None: if date.today() > (user.indexer.registration_expires + timedelta(1)): return render_error(request, ('The account with the email "%s" was never confirmed ' 'and has expired. You may <a href="' + \ urlresolvers.reverse('register') + \ '">re-register</a>. ') % esc(user.email), is_safe=True ) return render_error(request, ('The account with email "%s" has not yet been confirmed. ' 'You should receive an email that gives you a URL to visit ' 'to confirm your account. After you have visited that URL ' 'you will be able to log in and use your account. Please ' '<a href="mailto:%s">contact us</a> if you do not receive ' 'the email within a few hours.') % (esc(user.email), settings.EMAIL_CONTACT), is_safe=True) except Exception: pass if 'next' in request.POST: next = request.POST['next'] if re.match(r'/accounts/confirm/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('welcome') request.POST = post if re.match(r'/gcd-error/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('home') request.POST = post return standard_login(request, template_name=template_name)
def login(request, template_name): """ Do some pre-checking before handing off to the standard login view. If anything goes wrong just let the standard login handle it. """ if request.user.is_authenticated(): return HttpResponseRedirect(urlresolvers.reverse('default_profile')) try: if request.method == "POST": try: user = User.objects.get(email=request.POST['username']) except (User.DoesNotExist, User.MultipleObjectsReturned): user = User.objects.get(username=request.POST['username']) if user.indexer.registration_expires is not None: if date.today() > (user.indexer.registration_expires + timedelta(1)): return render_error(request, ('The account with the email "%s" was never confirmed ' 'and has expired. You may <a href="' + \ urlresolvers.reverse('register') + \ '">re-register</a>. ') % esc(user.email), is_safe=True ) return render_error( request, ('The account with email "%s" has not yet been confirmed. ' 'You should receive an email that gives you a URL to visit ' 'to confirm your account. After you have visited that URL ' 'you will be able to log in and use your account. Please ' '<a href="mailto:%s">contact us</a> if you do not receive ' 'the email within a few hours.') % (esc(user.email), settings.EMAIL_CONTACT), is_safe=True) except User.DoesNotExist: pass redirect_override = None if 'next' in request.POST: next = request.POST['next'] if re.match(r'/accounts/confirm/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('welcome') request.POST = post if re.match(r'/gcd-error/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('home') request.POST = post # The following test is what standard_login() does to disallow # redirects to different hosts, so we check if the host is in # our whitelist in order to override this decision netloc = urlparse.urlparse(next)[1] if (netloc and netloc != request.get_host() and netloc in settings.LOGIN_REDIRECT_WHITELIST): redirect_override = next response = standard_login( request, template_name=template_name, authentication_form=LongUsernameAuthenticationForm) if redirect_override and isinstance(response, HttpResponseRedirect): return HttpResponseRedirect(redirect_override) return response
def login(request, template_name): """ Do some pre-checking before handing off to the standard login view. If anything goes wrong just let the standard login handle it. """ if request.user.is_authenticated(): return HttpResponseRedirect(urlresolvers.reverse('default_profile')) try: if request.method == "POST": try: user = User.objects.get(email=request.POST['username']) except (User.DoesNotExist, User.MultipleObjectsReturned): user = User.objects.get(username=request.POST['username']) if user.indexer.registration_expires is not None: if date.today() > (user.indexer.registration_expires + timedelta(1)): return render_error(request, ('The account with the email "%s" was never confirmed ' 'and has expired. You may <a href="' + \ urlresolvers.reverse('register') + \ '">re-register</a>. ') % esc(user.email), is_safe=True ) return render_error(request, ('The account with email "%s" has not yet been confirmed. ' 'You should receive an email that gives you a URL to visit ' 'to confirm your account. After you have visited that URL ' 'you will be able to log in and use your account. Please ' '<a href="mailto:%s">contact us</a> if you do not receive ' 'the email within a few hours.') % (esc(user.email), settings.EMAIL_CONTACT), is_safe=True) except User.DoesNotExist: pass redirect_override = None if 'next' in request.POST: next = request.POST['next'] if re.match(r'/accounts/confirm/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('welcome') request.POST = post if re.match(r'/gcd-error/', next, flags=re.I): post = request.POST.copy() post['next'] = urlresolvers.reverse('home') request.POST = post # The following test is what standard_login() does to disallow # redirects to different hosts, so we check if the host is in # our whitelist in order to override this decision netloc = urlparse.urlparse(next)[1] if (netloc and netloc != request.get_host() and netloc in settings.LOGIN_REDIRECT_WHITELIST): redirect_override = next response = standard_login(request, template_name=template_name, authentication_form=LongUsernameAuthenticationForm) if redirect_override and isinstance(response, HttpResponseRedirect): return HttpResponseRedirect(redirect_override) return response