mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 18:30:53 +00:00
Enable add user in web and remove bind key id in registration form
This commit is contained in:
33
forms.py
Normal file
33
forms.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class AddUserForm(forms.Form):
|
||||
"""
|
||||
Form for adding a user.
|
||||
"""
|
||||
|
||||
email = forms.EmailField()
|
||||
password1 = forms.CharField(widget=forms.PasswordInput())
|
||||
password2 = forms.CharField(widget=forms.PasswordInput())
|
||||
|
||||
def clean_email(self):
|
||||
try:
|
||||
user = User.objects.get(email__iexact=self.cleaned_data['email'])
|
||||
except User.DoesNotExist:
|
||||
return self.cleaned_data['email']
|
||||
|
||||
raise forms.ValidationError(_("A user with this email already"))
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
Verifiy that the values entered into the two password fields
|
||||
match. Note that an error here will end up in
|
||||
``non_field_errors()`` because it doesn't apply to a single
|
||||
field.
|
||||
|
||||
"""
|
||||
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
|
||||
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
|
||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||
return self.cleaned_data
|
Reference in New Issue
Block a user