~danilo/linaro-license-protection/django-refactor-deployment

« back to all changes in this revision

Viewing changes to license_protected_downloads/openid_auth.py

Full refactoring with some cleanups (bzr mv files instead of deleting then adding them in a different place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
 
 
3
from django.conf import settings
 
4
from django.shortcuts import redirect
 
5
 
 
6
from django.http import HttpResponseForbidden
 
7
from django.contrib.auth.models import User, Group
 
8
 
 
9
class OpenIDAuth:
 
10
 
 
11
    @classmethod
 
12
    def process_openid_auth(cls, request, openid_teams):
 
13
 
 
14
        if not openid_teams:
 
15
            return None
 
16
 
 
17
        for openid_team in openid_teams:
 
18
            Group.objects.get_or_create(name=openid_team)
 
19
 
 
20
        if not request.user.is_authenticated():
 
21
            # Force OpenID login
 
22
            return redirect(settings.LOGIN_URL + "?next=" +  request.path)
 
23
 
 
24
        for group in request.user.groups.all():
 
25
            if group.name in openid_teams:
 
26
                return None
 
27
 
 
28
        return HttpResponseForbidden("Not Authorized")