76 self._sessions[session.sessionid] = session |
76 self._sessions[session.sessionid] = session |
77 # associate the connection to the current request |
77 # associate the connection to the current request |
78 req.set_session(session) |
78 req.set_session(session) |
79 return session |
79 return session |
80 |
80 |
81 def postlogin(self, req): |
81 def postlogin(self, req, session): |
82 """postlogin: the user has been authenticated, redirect to the original |
82 """postlogin: the user have been related to a session |
83 page (index by default) with a welcome message |
83 |
|
84 Both req and session are passed to this function because actually |
|
85 linking the request to the session is not yet done and not the |
|
86 responsability of this object. |
84 """ |
87 """ |
85 # Update last connection date |
88 # Update last connection date |
86 # XXX: this should be in a post login hook in the repository, but there |
89 # XXX: this should be in a post login hook in the repository, but there |
87 # we can't differentiate actual login of automatic session |
90 # we can't differentiate actual login of automatic session |
88 # reopening. Is it actually a problem? |
91 # reopening. Is it actually a problem? |
89 if 'last_login_time' in req.vreg.schema: |
92 if 'last_login_time' in req.vreg.schema: |
90 self._update_last_login_time(req) |
93 self._update_last_login_time(session) |
91 req.set_message(req._('welcome %s !') % req.user.login) |
94 req.set_message(req._('welcome %s !') % session.cnx.user().login) |
92 |
95 |
93 def _update_last_login_time(self, req): |
96 def _update_last_login_time(self, session): |
94 # XXX should properly detect missing permission / non writeable source |
97 # XXX should properly detect missing permission / non writeable source |
95 # and avoid "except (RepositoryError, Unauthorized)" below |
98 # and avoid "except (RepositoryError, Unauthorized)" below |
96 try: |
99 try: |
97 req.execute('SET X last_login_time NOW WHERE X eid %(x)s', |
100 cu = session.cnx.cursor() |
98 {'x' : req.user.eid}) |
101 cu.execute('SET X last_login_time NOW WHERE X eid %(x)s', |
99 req.cnx.commit() |
102 {'x' : session.cnx.user().eid}) |
|
103 session.cnx.commit() |
100 except (RepositoryError, Unauthorized): |
104 except (RepositoryError, Unauthorized): |
101 req.cnx.rollback() |
105 session.cnx.rollback() |
102 except Exception: |
106 except Exception: |
103 req.cnx.rollback() |
107 session.cnx.rollback() |
104 raise |
108 raise |
105 |
109 |
106 def close_session(self, session): |
110 def close_session(self, session): |
107 """close session on logout or on invalid session detected (expired out, |
111 """close session on logout or on invalid session detected (expired out, |
108 corrupted...) |
112 corrupted...) |