1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
34 from django import forms
35 from django.utils.translation import ugettext as _
36 from django.conf import settings
38 from astakos.im.models import User
41 ('Google','https://www.google.com/accounts/o8/id'),
42 ('Yahoo', 'http://yahoo.com/'),
43 ('AOL','http://openid.aol.com/%s/'),
45 ('MyOpenID','http://%s.myopenid.com/'),
46 ('LiveJournal', 'http://%s.livejournal.com/'),
47 ('Flickr', 'http://flickr.com/%s/'),
48 ('Technorati', 'http://technorati.com/people/technorati/%s/'),
49 ('Wordpress', 'http://%s.wordpress.com/'),
50 ('Blogger', 'http://%s.blogspot.com/'),
51 ('Verisign', 'http://%s.pip.verisignlabs.com/'),
52 ('Vidoop', 'http://%s.myvidoop.com/'),
53 ('ClaimID','http://claimid.com/%s')
56 class RegisterForm(forms.Form):
57 uniq = forms.CharField(widget=forms.widgets.TextInput())
58 provider = forms.CharField(widget=forms.TextInput(),
59 label=u'Identity Provider')
60 email = forms.EmailField(widget=forms.TextInput(),
61 label=_('Email address'))
62 realname = forms.CharField(widget=forms.TextInput(),
65 def __init__(self, *args, **kwargs):
66 super(forms.Form, self).__init__(*args, **kwargs)
68 #set readonly form fields
69 self.fields['provider'].widget.attrs['readonly'] = True
73 Validate that the uniq is alphanumeric and is not already
78 user = User.objects.get(uniq__iexact=self.cleaned_data['uniq'])
79 except User.DoesNotExist:
80 return self.cleaned_data['uniq']
81 raise forms.ValidationError(_("A user with that uniq already exists."))
83 class ShibbolethRegisterForm(RegisterForm):
86 class TwitterRegisterForm(RegisterForm):
89 class OpenidRegisterForm(RegisterForm):
90 openidurl = forms.ChoiceField(widget=forms.Select,
91 choices=((url, l) for l, url in openid_providers))
93 class LocalRegisterForm(RegisterForm):
94 """ local signup form"""
95 password = forms.CharField(widget=forms.PasswordInput(render_value=False),
97 password2 = forms.CharField(widget=forms.PasswordInput(render_value=False),
98 label=_('Confirm Password'))
100 def __init__(self, *args, **kwargs):
101 super(LocalRegisterForm, self).__init__(*args, **kwargs)
103 def clean_uniq(self):
105 Validate that the uniq is alphanumeric and is not already
110 user = User.objects.get(uniq__iexact=self.cleaned_data['uniq'])
111 except User.DoesNotExist:
112 return self.cleaned_data['uniq']
113 raise forms.ValidationError(_("A user with that uniq already exists."))
117 Verifiy that the values entered into the two password fields
118 match. Note that an error here will end up in
119 ``non_field_errors()`` because it doesn't apply to a single
123 if 'password' in self.cleaned_data and 'password2' in self.cleaned_data:
124 if self.cleaned_data['password'] != self.cleaned_data['password2']:
125 raise forms.ValidationError(_("The two password fields didn't match."))
126 return self.cleaned_data
128 class InvitedRegisterForm(RegisterForm):
129 inviter = forms.CharField(widget=forms.TextInput(),
130 label=_('Inviter Real Name'))
132 def __init__(self, *args, **kwargs):
133 super(RegisterForm, self).__init__(*args, **kwargs)
135 #set readonly form fields
136 self.fields['uniq'].widget.attrs['readonly'] = True
137 self.fields['inviter'].widget.attrs['readonly'] = True
138 self.fields['provider'].widget.attrs['provider'] = True
140 class InvitedLocalRegisterForm(LocalRegisterForm, InvitedRegisterForm):
143 class InvitedOpenidRegisterForm(OpenidRegisterForm, InvitedRegisterForm):
146 class InvitedTwitterRegisterForm(TwitterRegisterForm, InvitedRegisterForm):
149 class InvitedShibbolethRegisterForm(ShibbolethRegisterForm, InvitedRegisterForm):