improve lazysignup convert: more fields, redirect on done
This commit is contained in:
29
procat2/forms.py
Normal file
29
procat2/forms.py
Normal file
@ -0,0 +1,29 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm as UserCreationFormBase
|
||||
|
||||
|
||||
class UserCreationForm(UserCreationFormBase):
|
||||
"""Account creation with added email, first, and last names."""
|
||||
email = forms.EmailField(required=True)
|
||||
first_name = forms.CharField(required=True, label="First name")
|
||||
last_name = forms.CharField(required=True, label="Last name")
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')
|
||||
|
||||
def get_credentials(self):
|
||||
return {
|
||||
'username': self.cleaned_data['username'],
|
||||
'password': self.cleaned_data['password1']
|
||||
}
|
||||
|
||||
def save(self, commit=True):
|
||||
user = super(UserCreationForm, self).save(commit=False)
|
||||
user.email = self.cleaned_data["email"]
|
||||
user.first_name = self.cleaned_data["first_name"]
|
||||
user.last_name = self.cleaned_data["last_name"]
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
@ -17,13 +17,19 @@ from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
from dashboard.views import dashboard
|
||||
from lazysignup.views import convert
|
||||
|
||||
from .forms import UserCreationForm
|
||||
from .views import lazy_convert_done
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('', dashboard, name='home'),
|
||||
path('dashboard', dashboard, name='dashboard'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
path('convert/', include('lazysignup.urls')),
|
||||
path('convert/', convert, { 'form_class': UserCreationForm }, name='lazysignup_convert'),
|
||||
path('convert/done/', lazy_convert_done, name='lazysignup_convert_done'),
|
||||
]
|
||||
|
||||
# accounts/login/ [name='login']
|
||||
|
||||
9
procat2/views.py
Normal file
9
procat2/views.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
def lazy_convert_done(request):
|
||||
"""Called after converting a lazy user."""
|
||||
messages.info(request, _('Account created. Welcome!'))
|
||||
return redirect('home')
|
||||
Reference in New Issue
Block a user