26 lines
No EOL
881 B
Python
26 lines
No EOL
881 B
Python
from django.contrib.auth.views import LoginView as Login, LogoutView as Logout
|
|
from django.http.response import HttpResponseRedirect
|
|
from django.contrib.auth import login
|
|
from django.shortcuts import resolve_url
|
|
from django.conf import settings
|
|
|
|
from .forms import RegistrationForm
|
|
from .models import User
|
|
|
|
class LoginView(Login):
|
|
template_name = "localauth/register.html"
|
|
|
|
class LogoutView(Logout):
|
|
next_page = "/"
|
|
|
|
class RegistrationView(Login):
|
|
form_class = RegistrationForm
|
|
template_name = "localauth/register.html"
|
|
|
|
def form_valid(self, form):
|
|
user = User.objects.create_user(form.cleaned_data["email"], form.cleaned_data["password1"])
|
|
login(self.request, user)
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
def get_default_redirect_url(self):
|
|
return resolve_url(self.next_page or settings.REGISTER_REDIRECT_URL) |