]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-828, Support fullname to real_name mapping from OpenID providers
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 4 Apr 2012 23:10:46 +0000 (23:10 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 4 Apr 2012 23:10:46 +0000 (23:10 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1243 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms/auth.py
forum/forms/general.py
forum/skins/default/templates/auth/complete.html
forum/views/auth.py
forum_modules/openidauth/consumer.py
osqa.iml

index 9bf2d671e40bbf7e2158e01145c2382066be73c2..0d07ce81ad8d2d7ea4f896a6338822d85cc7d0d4 100644 (file)
@@ -1,4 +1,4 @@
-from general import NextUrlField,  UserNameField,  UserEmailField, SetPasswordForm
+from general import NextUrlField,  UserNameField,  UserEmailField, UserRealNameField, SetPasswordForm
 from forum.models import Question, User
 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import ugettext as _
@@ -10,6 +10,7 @@ class SimpleRegistrationForm(forms.Form):
     next = NextUrlField()
     username = UserNameField()
     email = UserEmailField()
+    real_name = UserRealNameField()
 
 class TemporaryLoginRequestForm(forms.Form):
     def __init__(self, data=None):
index aa4282e9efa4714333a09d2eab4f2ad4d7d0d9fc..01c528bb854a7295e05e6ad6cd0523d6150358af 100644 (file)
@@ -126,6 +126,32 @@ class UserEmailField(forms.EmailField):
         else:
             return email 
 
+class UserRealNameField(StrippedNonEmptyCharField):
+    def __init__(self, db_model=User, db_field='real_name', must_exist=True, skip_clean=False, label=_('Your real name'),**kw):
+        self.must_exist = must_exist
+        self.skip_clean = skip_clean
+        self.db_model = db_model
+        self.db_field = db_field
+        error_messages={'required':_('Real name is required')
+                    }
+        if 'error_messages' in kw:
+            error_messages.update(kw['error_messages'])
+            del kw['error_messages']
+        super(UserRealNameField,self).__init__(max_length=100,
+                widget=forms.TextInput(attrs=login_form_widget_attrs),
+                label=label,
+                error_messages=error_messages,
+                **kw
+                )
+
+    def clean(self, real_name):
+        if self.skip_clean == True:
+            return real_name
+        try:
+            return super(UserRealNameField, self).clean(real_name)
+        except forms.ValidationError:
+            raise forms.ValidationError(self.error_messages['required'])
+
 class SetPasswordForm(forms.Form):
     password1 = forms.CharField(widget=forms.PasswordInput(attrs=login_form_widget_attrs),
                                 label=_('choose password'),
index 79f10dcf27bf9b1729dd33cdb48f392cf1e157c6..1c327bfeb4b0d59ef9443224ce54af3083a19ccc 100644 (file)
                 {% endif %}
                 {{ form1.email }}
             </div>
+            <div class="form-row-vertical margin-bottom">
+                <label for="id_real_name">{{ form1.real_name.label }}</label>
+                {% if form1.real_name.errors %}
+                    <p class="error">{{ form1.real_name.errors|join:", " }}</p>
+                {% endif %}
+                {{ form1.real_name }}
+            </div>
             {% if form1.password1 %}
                 <div class="form-row-vertical margin-bottom">
                     <label for="password1_id">{{ form1.password1.label }}</label>
index 92aa894c817ad870f5765debd30dfad061026dca..3b78eed56daf1d2d8025a3fea3d3d926e47d99e0 100644 (file)
@@ -157,7 +157,7 @@ def external_register(request):
         form1 = SimpleRegistrationForm(request.POST)
 
         if form1.is_valid():
-            user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email'])
+            user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email'], real_name=form1.cleaned_data['real_name'])
             user_.email_isvalid = request.session.get('auth_validated_email', '') == form1.cleaned_data['email']
             user_.set_unusable_password()
 
@@ -208,6 +208,7 @@ def external_register(request):
 
         username = user_data.get('username', '')
         email = user_data.get('email', '')
+        real_name = user_data.get('real_name', '')
 
         if email:
             request.session['auth_validated_email'] = email
@@ -216,6 +217,7 @@ def external_register(request):
         'next': '/',
         'username': username,
         'email': email,
+        'real_name': real_name,
         })
 
     provider_context = AUTH_PROVIDERS[request.session['auth_provider']].context
index aa24a36c69ba77bf341f9c1c635fd82106baf818..29a637562f13ec9281b6ef0ad92f65214edafbd3 100644 (file)
@@ -32,7 +32,8 @@ class OpenIdAbstractAuthConsumer(AuthenticationConsumer):
     sreg_attributes = {
         "required": {
             "email": "email",
-            "nickname": "username"
+            "nickname": "username",
+            "fullname": "real_name"
         }
     }
 
index aa15d1094a943ac3d4a4cc5dba35f9d0efe12591..ff76cadacc96367efa763ae07f21721ae9e822e1 100644 (file)
--- a/osqa.iml
+++ b/osqa.iml
@@ -4,8 +4,8 @@
     <facet type="django" name="Django">\r
       <configuration>\r
         <option name="rootFolder" value="$MODULE_DIR$" />\r
-        <option name="templatesFolder" value="$MODULE_DIR$/forum/skins/default/templates" />\r
         <option name="settingsModule" value="settings.py" />\r
+        <option name="manageScript" value="manage.py" />\r
       </configuration>\r
     </facet>\r
   </component>\r