Last active
September 9, 2020 12:25
-
-
Save NerdPraise/c6d55b9302945f0ff95f133d3362d6e5 to your computer and use it in GitHub Desktop.
Views for Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SigninView(views.LoginView): | |
""" | |
Sign in view template | |
""" | |
template_name = "registration/login.html" | |
authentication_form = SignInForm | |
def register(request): | |
""" | |
Create an account on form submitting | |
""" | |
if request.POST: | |
form = RegisterForm(request.POST) | |
if form.is_valid(): | |
form.save() | |
email = form.cleaned_data["email"] | |
password = form.cleaned_data["password1"] | |
user = authenticate(request, email=email, password=password) | |
login(request, user) | |
return redirect("student") | |
else: | |
form = RegisterForm() | |
return render(request, "registration/register.html", {"form": form}) | |
def logout(request): | |
""" | |
Logout view | |
""" | |
return views.logout_then_login(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment