2012-03-09 02:31:35 +00:00
|
|
|
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
|
2012-04-26 12:33:24 +00:00
|
|
|
|
2012-03-09 02:31:35 +00:00
|
|
|
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):
|
2012-04-26 12:33:24 +00:00
|
|
|
email = self.cleaned_data['email']
|
2012-06-25 12:42:19 +00:00
|
|
|
emailuser = ccnet_threaded_rpc.get_emailuser(email)
|
2012-04-26 12:33:24 +00:00
|
|
|
if not emailuser:
|
2012-03-09 02:31:35 +00:00
|
|
|
return self.cleaned_data['email']
|
2012-04-26 12:33:24 +00:00
|
|
|
else:
|
|
|
|
raise forms.ValidationError(_("A user with this email already"))
|
2012-03-09 02:31:35 +00:00
|
|
|
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
|