Correction
[cyril.git] / Apps / roundup / auf_roa.py
CommitLineData
849ecd4a
CR
1import hashlib, simplejson, urllib
2
3from roundup.cgi.actions import LoginAction
4from roundup.i18n import _
5
6class 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):
85d46d7d 12 username = username.replace (self.auf_email_suffix, "")
849ecd4a
CR
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" \
4a23a9bc 18 % (self.auf_roa_url, email, md5pass)
849ecd4a
CR
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 props = {'realname': "%s %s" % (user.first_name, user.last_name),
32 'username': user.email,
33 'address': user.email}
34 self.journaltag = 'admin'
35 cl = self.db.user
36 props['roles'] = self.db.config.NEW_WEB_USER_ROLES
37 self.userid = cl.create (**props)
38 self.db.commit ()
39 self.client.userid = self.db.user.lookup(self.client.user)
40
878367f0
CR
41def init(instance):
42 instance.registerAction('login', AufRoaLoginAction)
849ecd4a 43