From: jordan Date: Wed, 4 Apr 2012 23:10:46 +0000 (+0000) Subject: OSQA-828, Support fullname to real_name mapping from OpenID providers X-Git-Tag: live~74 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/fa657e16956d77027de1594980e27ffef3ff82c1?ds=sidebyside OSQA-828, Support fullname to real_name mapping from OpenID providers git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1243 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/forms/auth.py b/forum/forms/auth.py index 9bf2d67..0d07ce8 100644 --- a/forum/forms/auth.py +++ b/forum/forms/auth.py @@ -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): diff --git a/forum/forms/general.py b/forum/forms/general.py index aa4282e..01c528b 100644 --- a/forum/forms/general.py +++ b/forum/forms/general.py @@ -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'), diff --git a/forum/skins/default/templates/auth/complete.html b/forum/skins/default/templates/auth/complete.html index 79f10dc..1c327bf 100644 --- a/forum/skins/default/templates/auth/complete.html +++ b/forum/skins/default/templates/auth/complete.html @@ -50,6 +50,13 @@ {% endif %} {{ form1.email }} +
+ + {% if form1.real_name.errors %} +

{{ form1.real_name.errors|join:", " }}

+ {% endif %} + {{ form1.real_name }} +
{% if form1.password1 %}
diff --git a/forum/views/auth.py b/forum/views/auth.py index 92aa894..3b78eed 100644 --- a/forum/views/auth.py +++ b/forum/views/auth.py @@ -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 diff --git a/forum_modules/openidauth/consumer.py b/forum_modules/openidauth/consumer.py index aa24a36..29a6375 100644 --- a/forum_modules/openidauth/consumer.py +++ b/forum_modules/openidauth/consumer.py @@ -32,7 +32,8 @@ class OpenIdAbstractAuthConsumer(AuthenticationConsumer): sreg_attributes = { "required": { "email": "email", - "nickname": "username" + "nickname": "username", + "fullname": "real_name" } } diff --git a/osqa.iml b/osqa.iml index aa15d10..ff76cad 100644 --- a/osqa.iml +++ b/osqa.iml @@ -4,8 +4,8 @@