summaryrefslogtreecommitdiff
path: root/baserock_openid_provider/baserock_openid_provider/views.py
blob: d067f66a3af3cf3a17c2c7aa0051d59b2eee76fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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.


import registration.backends.default.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.default.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, form):
        # Calling the base class first means that we don't have to copy and
        # paste the contents of the register() function, but it has the
        # downside that we don't know the user's name when we send the
        # activation email.
        superclass = super(RegistrationViewWithNames, self)
        user = superclass.register(form)

        user.first_name = form.cleaned_data['first_name']
        user.last_name = form.cleaned_data['last_name']
        user.save()

        return user


registration.backends.default.views.RegistrationView = RegistrationViewWithNames