Guest User

Untitled

a guest
Jul 28th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. def register(request):
  2. if request.method == 'POST':
  3. user_form = UserRegistrationForm(request.POST)
  4. if user_form.is_valid():
  5. new_user = user_form.save(commit=False)
  6. new_user.set_password(user_form.cleaned_data['password'])
  7. # new_user.save()
  8. return render(request, 'accounts/register_done.html', {'new_user': new_user})
  9. else:
  10. user_form = UserRegistrationForm()
  11. return render(request, 'accounts/register.html', {'user_form': user_form})
  12.  
  13. class UserRegistrationForm(forms.ModelForm):
  14.  
  15. username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Логин'}))
  16. password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Пароль'}))
  17. password2 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Повторите пароль'}))
  18.  
  19. class Meta:
  20. model = User
  21. fields = ('username',)
  22.  
  23. def clean_password2(self):
  24. cd = self.cleaned_data
  25. if cd['password'] != cd['password2']:
  26. raise forms.ValidationError('Пароли не совпадают!')
  27. return cd['password2']
Add Comment
Please, Sign In to add comment