diff options
author | Leif Johansson <leifj@sunet.se> | 2011-05-10 09:44:56 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-05-10 09:44:56 +0200 |
commit | 4e14a262829b763a6bcbd7e8fc376b51c1094509 (patch) | |
tree | 5cbafe2fd4aa6f6a96debe88e20eb987d5e5e54c /src/meetingtools | |
parent | 4dccf3f3a8b06d47122e8e9ac995af0eee9bcec7 (diff) |
export session as random password to acp
Diffstat (limited to 'src/meetingtools')
-rw-r--r-- | src/meetingtools/ac/api.py | 13 | ||||
-rw-r--r-- | src/meetingtools/apps/auth/views.py | 13 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/meetingtools/ac/api.py b/src/meetingtools/ac/api.py index 59aa2d8..c26cd29 100644 --- a/src/meetingtools/ac/api.py +++ b/src/meetingtools/ac/api.py @@ -14,6 +14,7 @@ from lxml import etree import pprint from meetingtools.site_logging import logger import lxml +from django.http import HttpResponseRedirect class ACPException(Exception): def __init__(self, value): @@ -63,12 +64,13 @@ def _getset(dict,key,value=None): class ACPClient(): - def __init__(self,url,username=None,password=None): + def __init__(self,url,username=None,password=None,cache=True): self.url = url self.session = None if username and password: self.login(username,password) - self._cache = {'login':{},'group':{}} + if cache: + self._cache = {'login':{},'group':{}} def request(self,method,p={},raise_error=False): if self.session: @@ -99,10 +101,17 @@ class ACPClient(): return r; + def redirect_to(self,url): + if self.session: + return HttpResponseRedirect("%s?BREEZESESSION=%s" % (url,self.session)) + else: + return HttpResponseRedirect(url) + def login(self,username,password): result = self.request('login',{'login':username,'password':password}) if result.is_error(): raise result.exception() + return result def find_or_create_principal(self,key,value,type,dict): if not self._cache.has_key(type): diff --git a/src/meetingtools/apps/auth/views.py b/src/meetingtools/apps/auth/views.py index 8af2e1a..b1f9567 100644 --- a/src/meetingtools/apps/auth/views.py +++ b/src/meetingtools/apps/auth/views.py @@ -16,6 +16,7 @@ from django.shortcuts import render_to_response from django.contrib import auth from django_co_connector.models import co_import_from_request, add_member,\ remove_member +import random, string def meta(request,attr): v = request.META.get(attr) @@ -60,8 +61,7 @@ def login(request): def join_group(group,**kwargs): user = kwargs['user'] acc = _acc_for_user(user) - connect_api = ac_api(acc) - + connect_api = ac_api(acc) principal = connect_api.find_principal("login", user.username, "user") if principal: gp = connect_api.find_group(group.name) @@ -83,6 +83,11 @@ def leave_group(group,**kwargs): add_member.connect(join_group,sender=Group) remove_member.connect(leave_group,sender=Group) +def _random_key(length=20): + rg = random.SystemRandom() + alphabet = string.letters + string.digits + return str().join(rg.choice(alphabet) for _ in range(length)) + def accounts_login_federated(request): if request.user.is_authenticated(): profile,created = UserProfile.objects.get_or_create(user=request.user) @@ -127,12 +132,16 @@ def accounts_login_federated(request): acc = _acc_for_user(request.user) connect_api = ac_api_client(request, acc) # make sure the principal is created before shooting off + key = _random_key() + request.session['ac_key'] = key principal = connect_api.find_or_create_principal("login", request.user.username, "user", {'type': "user", 'has-children': "0", 'first-name':fn, 'last-name':ln, 'email':mail, + 'send-email': 0, + 'password': key, 'login':request.user.username, 'ext-login':request.user.username}) |