1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-29 19:54:53 +00:00
seahub/forms.py

35 lines
1.2 KiB
Python
Raw Normal View History

from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
2012-06-25 12:42:19 +00:00
from seaserv import ccnet_rpc, ccnet_threaded_rpc
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):
email = self.cleaned_data['email']
2012-06-25 12:42:19 +00:00
emailuser = ccnet_threaded_rpc.get_emailuser(email)
if not emailuser:
return self.cleaned_data['email']
else:
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