diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-23 19:04:45 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-26 11:28:11 +0000 |
commit | 7a1db64930b2f5373cb7145783cb6afd17acd855 (patch) | |
tree | 75af4e2389b7f27c60c9f33d612f1d1a47b66ffa /baserock_openid_provider | |
parent | b04784aa50d4dbea02f095161815ba6752802069 (diff) | |
download | infrastructure-7a1db64930b2f5373cb7145783cb6afd17acd855.tar.gz |
openid_provider: Require user to provide a full name on registration
This is needed for Storyboard to be able to use the OpenID provider: it
uses the openid.fullname property as the user's display name.
Diffstat (limited to 'baserock_openid_provider')
-rw-r--r-- | baserock_openid_provider/baserock_openid_provider/forms.py | 29 | ||||
-rw-r--r-- | baserock_openid_provider/baserock_openid_provider/views.py | 36 |
2 files changed, 64 insertions, 1 deletions
diff --git a/baserock_openid_provider/baserock_openid_provider/forms.py b/baserock_openid_provider/baserock_openid_provider/forms.py new file mode 100644 index 00000000..dd6a414d --- /dev/null +++ b/baserock_openid_provider/baserock_openid_provider/forms.py @@ -0,0 +1,29 @@ +# Copyright (C) 2015 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +from registration.forms import RegistrationForm + +from django import forms +from django.utils.translation import ugettext_lazy as _ + + +class RegistrationFormWithNames(RegistrationForm): + # I'd rather just have a 'Full name' box, but django.contrib.auth is + # already set up to separate first_name and last_name. + + first_name = forms.CharField(label=_("First name(s)"), + required=False) + last_name = forms.CharField(label=_("Surname")) diff --git a/baserock_openid_provider/baserock_openid_provider/views.py b/baserock_openid_provider/baserock_openid_provider/views.py index 5d80186e..3efaf923 100644 --- a/baserock_openid_provider/baserock_openid_provider/views.py +++ b/baserock_openid_provider/baserock_openid_provider/views.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Codethink Limited +# Copyright (C) 2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,8 +14,42 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import registration.backends.simple.views + +from registration import signals +from registration.users import UserModel + +from django.contrib.auth import authenticate +from django.contrib.auth import login from django.shortcuts import render +from . import forms + def index(request): return render(request, '../templates/index.html') + + +class RegistrationViewWithNames(registration.backends.simple.views.RegistrationView): + # Overrides the django-registration default view so that the extended form + # including the full name gets used. + form_class = forms.RegistrationFormWithNames + + def register(self, request, **cleaned_data): + # It's a shame that we have to override the whole class here. We could + # patch django-registration(-redux) to avoid the need. + username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'] + first_name, last_name = cleaned_data['first_name'], cleaned_data['last_name'] + UserModel().objects.create_user(username, email, password, + first_name=first_name, + last_name=last_name) + + new_user = authenticate(username=username, password=password) + login(request, new_user) + signals.user_registered.send(sender=self.__class__, + user=new_user, + request=request) + return new_user + + +registration.backends.simple.views.RegistrationView = RegistrationViewWithNames |