Completed
Push — master ( e187ac...8aa8f5 )
by Peter
07:52
created

LoginView   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
1
import uuid
2
from django.core.urlresolvers import reverse
3
from django.views.generic import RedirectView
4
from django.core.exceptions import PermissionDenied
5
from django.shortcuts import redirect
6
7
from opensubmit import settings
8
from opensubmit.social import passthrough
9
from opensubmit.security import make_admin, make_tutor, make_owner
10
11
12
def assign_role(backend, user, response, *args, **kwargs):
13
    '''
14
    Part of the Python Social Auth Pipeline.
15
    Checks if the created demo user should be pushed into some group.
16
    '''
17
    if backend.name is 'passthrough' and settings.DEMO is True and 'role' in kwargs['request'].session[passthrough.SESSION_VAR]:
18
        role = kwargs['request'].session[passthrough.SESSION_VAR]['role']
19
        if role == 'tutor':
20
            make_tutor(user)
21
        if role == 'admin':
22
            make_admin(user)
23
        if role == 'owner':
24
            make_owner(user)
25
26
27
class LoginView(RedirectView):
28
    permanent = False
29
    pattern_name = 'dashboard'
30
31
    def get(self, request, role):
32
        if settings.DEMO is True:
33
            data = {'id': str(uuid.uuid4()), 'role': role}
34
            request.session[passthrough.SESSION_VAR] = data  # this enables the login
35
            return redirect(reverse('social:begin', args=['passthrough']))
36
        else:
37
            raise PermissionDenied
38