1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-03 21:46:47 +00:00
seahub/forms.py

34 lines
1.1 KiB
Python

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