b3a922de86562d9ec8c86e959c495d9e2249ec15
[cyril.git] / Apps / roundup / auf_roa.py
1 import hashlib, simplejson, urllib
2
3 from roundup.cgi.actions import LoginAction
4 from roundup.i18n import _
5
6 class AufRoaLoginAction(LoginAction):
7 auf_roa_url = 'http://authentification.auf.org/auth/user/'
8 auf_email_suffix = "@auf.org"
9
10 def verifyLogin(self, username, password):
11 if username.endswith (self.auf_email_suffix):
12 username = username.replace (self.auf_email_suffix, "")
13
14 email = "%s%s" % (username, self.auf_email_suffix)
15 md5pass = hashlib.md5 (password).hexdigest ()
16
17 url = "%s?filter_email=%s&filter_password=%s&format=json" \
18 % (self.auf_roa_url, email, md5pass)
19
20 user = None
21 try:
22 ud = urllib.urlopen (url)
23 list = simplejson.load (ud)
24 ud.close ()
25 user = list[0]
26 except:
27 self.client.make_user_anonymous()
28 self.client.error_message.append(_("Compte invalide ou erreur ROA"))
29 return
30
31 try:
32 self.client.userid = self.db.user.lookup(self.client.user)
33 except:
34 props = {'realname': "%s %s" % (user['first_name'], user['last_name']),
35 'username': user['email'],
36 'address': user['email']}
37 self.journaltag = 'admin'
38 cl = self.db.user
39 props['roles'] = self.db.config.NEW_WEB_USER_ROLES
40 self.userid = cl.create (**props)
41 self.db.commit ()
42 self.client.userid = self.db.user.lookup(self.client.user)
43
44 def init(instance):
45 instance.registerAction('login', AufRoaLoginAction)
46