Ajout roundup/auf_roa.py
authorCyril Robert <Cyril Robert crobert@inverse.ca>
Fri, 19 Feb 2010 16:53:05 +0000 (11:53 -0500)
committerCyril Robert <Cyril Robert crobert@inverse.ca>
Fri, 19 Feb 2010 16:53:05 +0000 (11:53 -0500)
Apps/roundup/auf_roa.py [new file with mode: 0644]
Scripts/SigmaCopyUsers/copy_users.py

diff --git a/Apps/roundup/auf_roa.py b/Apps/roundup/auf_roa.py
new file mode 100644 (file)
index 0000000..101c788
--- /dev/null
@@ -0,0 +1,43 @@
+import hashlib, simplejson, urllib
+
+from roundup.cgi.actions import LoginAction
+from roundup.i18n import _
+
+class AufRoaLoginAction(LoginAction):
+    auf_roa_url = 'http://authentification.auf.org/auth/user/'
+    auf_email_suffix = "@auf.org"
+
+    def verifyLogin(self, username, password):
+        if username.endswith (self.auf_email_suffix):
+            username = username.remplace (self.auf_email_suffix, "")
+
+        email = "%s%s" % (username, self.auf_email_suffix)
+        md5pass = hashlib.md5 (password).hexdigest ()
+
+        url = "%s?filter_email=%s&filter_password=%s&format=json" \
+                % (self.auf_roa_url, md5pass, email)
+
+        user = None
+        try:
+            ud = urllib.urlopen (url)
+            list = simplejson.load (ud)
+            ud.close ()
+            user = list[0]
+        except:
+            self.client.make_user_anonymous()
+            self.client.error_message.append(_("Compte invalide ou erreur ROA"))
+            return
+
+        props = {'realname': "%s %s" % (user.first_name, user.last_name),
+                 'username': user.email,
+                 'address': user.email}
+        self.journaltag = 'admin'
+        cl = self.db.user
+        props['roles'] = self.db.config.NEW_WEB_USER_ROLES
+        self.userid = cl.create (**props)
+        self.db.commit ()
+        self.client.userid = self.db.user.lookup(self.client.user)
+
+    def init(instance):
+        instance.registerAction('login', AufRoaLoginAction)
+
index ac740b5..6173209 100755 (executable)
@@ -49,6 +49,12 @@ if __name__ == "__main__":
         d.execute ("""SELECT `id` FROM `auth_user` WHERE `username`=%s""", utilisateur)
         user_id = d.fetchone()[0]
 
+        d.execute ("""SELECT `id` FROM `ref_employe` WHERE `courriel`=%s""", email)
+        matricule = d.fetchone()[0]
+        
+        d.execute ("""INSERT INTO `www_aufuser` (user_ptr_id, employe_id) 
+                      VALUES (%s, %s)""", (user_id, matricule))
+
         if re.match (r'AB\[\d+\]$', habilitation):
             bureau = re.search (r'\[(\d+)\]', habilitation).group(1)
             group = responsables[int(bureau)]