def account(request, template="account.html"): """ Display and handle both the login and signup forms. """ login_form = LoginForm() signup_form = SignupForm() if request.method == "POST": posted_form = None message = "" if request.POST.get("login") is not None: login_form = LoginForm(request.POST) if login_form.is_valid(): posted_form = login_form message = _("Successfully logged in") else: signup_form = SignupForm(request.POST) if signup_form.is_valid(): signup_form.save() posted_form = signup_form message = _("Successfully signed up") if posted_form is not None: posted_form.login(request) info(request, message) return redirect(request.GET.get("next", "/")) context = {"login_form": login_form, "signup_form": signup_form} return render(request, template, context)
def account(request, template="account.html"): """ Display and handle both the login and signup forms. """ login_form = LoginForm(request) signup_form = SignupForm(request) if request.method == "POST": posted_form = None message = "" if request.POST.get("login") is not None: login_form = LoginForm(request, request.POST) if login_form.is_valid(): posted_form = login_form message = _("Successfully logged in") else: signup_form = SignupForm(request, request.POST) if signup_form.is_valid(): new_user = signup_form.save() if not new_user.is_active: send_verification_mail(request, new_user) info(request, _("A verification email has been sent with " "a link for activating your account.")) else: posted_form = signup_form message = _("Successfully signed up") if posted_form is not None: posted_form.login(request) info(request, message) return redirect(request.GET.get("next", "/")) context = {"login_form": login_form, "signup_form": signup_form} return render(request, template, context)