| | 182 | def _get_name_for_cookie(self, req, cookie): |
|---|
| | 183 | name = auth.LoginModule._get_name_for_cookie(self, req, cookie) |
|---|
| | 184 | if name and not req.incookie.has_key('trac_auth_session'): |
|---|
| | 185 | self.env.log.debug('Updating auth cookie %s for user %s' % |
|---|
| | 186 | (cookie.value, name)) |
|---|
| | 187 | db = self.env.get_db_cnx() |
|---|
| | 188 | cursor = db.cursor() |
|---|
| | 189 | cursor.execute('UPDATE auth_cookie SET time=%s WHERE cookie=%s', |
|---|
| | 190 | (int(time.time()), cookie.value)) |
|---|
| | 191 | req.outcookie['trac_auth'] = cookie.value |
|---|
| | 192 | req.outcookie['trac_auth']['path'] = self.env.href() |
|---|
| | 193 | req.outcookie['trac_auth']['expires'] = 86400 * 30 |
|---|
| | 194 | req.outcookie['trac_auth_session'] = '1' |
|---|
| | 195 | req.outcookie['trac_auth_session']['path'] = self.env.href() |
|---|
| | 196 | return name |
|---|
| | 197 | |
|---|
| | 206 | def _do_logout(self, req): |
|---|
| | 207 | """Log the user out. |
|---|
| | 208 | |
|---|
| | 209 | Simply deletes the corresponding record from the auth_cookie table. |
|---|
| | 210 | """ |
|---|
| | 211 | if req.authname == 'anonymous': |
|---|
| | 212 | # Not logged in |
|---|
| | 213 | return |
|---|
| | 214 | |
|---|
| | 215 | # While deleting this cookie we also take the opportunity to delete |
|---|
| | 216 | # cookies older than 30 days |
|---|
| | 217 | db = self.env.get_db_cnx() |
|---|
| | 218 | cursor = db.cursor() |
|---|
| | 219 | cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s", |
|---|
| | 220 | (req.authname, int(time.time()) - 86400 * 30)) |
|---|
| | 221 | db.commit() |
|---|
| | 222 | self._expire_cookie(req) |
|---|
| | 223 | |
|---|