Show login target on the login screen
[cascardo/ipsilon.git] / ipsilon / login / common.py
index 2b3ac19..94284b0 100755 (executable)
@@ -45,14 +45,21 @@ class LoginManagerBase(PluginObject, Log):
 
     def auth_successful(self, trans, username, auth_type=None, userdata=None):
         session = UserSession()
 
     def auth_successful(self, trans, username, auth_type=None, userdata=None):
         session = UserSession()
-        session.login(username, userdata)
 
         if self.info:
             userattrs = self.info.get_user_attrs(username)
             if userdata:
 
         if self.info:
             userattrs = self.info.get_user_attrs(username)
             if userdata:
-                userdata.update(userattrs or {})
+                userdata.update(userattrs.get('userdata', {}))
             else:
             else:
-                userdata = userattrs
+                userdata = userattrs.get('userdata', {})
+
+            # merge groups and extras from login plugin and info plugin
+            userdata['groups'] = list(set(userdata.get('groups', []) +
+                                          userattrs.get('groups', [])))
+
+            userdata['extras'] = userdata.get('extras', {})
+            userdata['extras'].update(userattrs.get('extras', {}))
+
             self.debug("User %s attributes: %s" % (username, repr(userdata)))
 
         if auth_type:
             self.debug("User %s attributes: %s" % (username, repr(userdata)))
 
         if auth_type:
@@ -61,6 +68,9 @@ class LoginManagerBase(PluginObject, Log):
             else:
                 userdata = {'auth_type': auth_type}
 
             else:
                 userdata = {'auth_type': auth_type}
 
+        # create session login including all the userdata just gathered
+        session.login(username, userdata)
+
         # save username into a cookie if parent was form base auth
         if auth_type == 'password':
             cookie = SecureCookie(USERNAME_COOKIE, username)
         # save username into a cookie if parent was form base auth
         if auth_type == 'password':
             cookie = SecureCookie(USERNAME_COOKIE, username)
@@ -77,6 +87,7 @@ class LoginManagerBase(PluginObject, Log):
         # on direct login the UI (ie not redirected by a provider) we ned to
         # remove the transaction cookie as it won't be needed anymore
         if trans.provider == 'login':
         # on direct login the UI (ie not redirected by a provider) we ned to
         # remove the transaction cookie as it won't be needed anymore
         if trans.provider == 'login':
+            self.debug('Wiping transaction data')
             trans.wipe()
         raise cherrypy.HTTPRedirect(redirect)
 
             trans.wipe()
         raise cherrypy.HTTPRedirect(redirect)
 
@@ -199,8 +210,10 @@ class LoginFormBase(LoginPageBase):
         if username is None:
             username = ''
 
         if username is None:
             username = ''
 
+        target = None
         if self.trans is not None:
             tid = self.trans.transaction_id
         if self.trans is not None:
             tid = self.trans.transaction_id
+            target = self.trans.retrieve().get('login_target')
         if tid is None:
             tid = ''
 
         if tid is None:
             tid = ''
 
@@ -213,6 +226,7 @@ class LoginFormBase(LoginPageBase):
             "description": self.lm.help_text,
             "next_url": next_url,
             "username": username,
             "description": self.lm.help_text,
             "next_url": next_url,
             "username": username,
+            "login_target": target,
         }
         context.update(kwargs)
         if self.trans is not None:
         }
         context.update(kwargs)
         if self.trans is not None: