You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
# -*- coding: utf-8 -*-
|
|
from access.models import User
|
|
from django.contrib.auth.forms import ReadOnlyPasswordHashField
|
|
from django import forms
|
|
|
|
|
|
class UserCreationForm(forms.ModelForm):
|
|
password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
|
|
password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = '__all__'
|
|
|
|
def clean_password2(self):
|
|
password1 = self.cleaned_data.get("password1")
|
|
password2 = self.cleaned_data.get("password2")
|
|
if password1 and password2 and password1 != password2:
|
|
raise forms.ValidationError("Passwords don't match")
|
|
return password2
|
|
|
|
def save(self, commit=True):
|
|
user = super(UserCreationForm, self).save(commit=False)
|
|
user.set_password(self.cleaned_data["password1"])
|
|
if commit:
|
|
user.save()
|
|
return user
|
|
|
|
|
|
class UserChangeForm(forms.ModelForm):
|
|
password = ReadOnlyPasswordHashField()
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = '__all__'
|
|
|
|
def clean_password(self):
|
|
return self.initial["password"] |