| | 376 | def _get_name_for_cookie(self, req, cookie): |
|---|
| | 377 | name = auth.LoginModule._get_name_for_cookie(self, req, cookie) |
|---|
| | 378 | if name and not req.incookie.has_key('trac_auth_session'): |
|---|
| | 379 | self.env.log.debug('Updating auth cookie %s for user %s' % |
|---|
| | 380 | (cookie.value, name)) |
|---|
| | 381 | db = self.env.get_db_cnx() |
|---|
| | 382 | cursor = db.cursor() |
|---|
| | 383 | cursor.execute('UPDATE auth_cookie SET time=%s WHERE cookie=%s', |
|---|
| | 384 | (int(time.time()), cookie.value)) |
|---|
| | 385 | req.outcookie['trac_auth'] = cookie.value |
|---|
| | 386 | req.outcookie['trac_auth']['path'] = self.env.href() |
|---|
| | 387 | req.outcookie['trac_auth']['expires'] = 86400 * 30 |
|---|
| | 388 | req.outcookie['trac_auth_session'] = '1' |
|---|
| | 389 | req.outcookie['trac_auth_session']['path'] = self.env.href() |
|---|
| | 390 | return name |
|---|
| | 391 | |
|---|
| | 400 | def _do_logout(self, req): |
|---|
| | 401 | """Log the user out. |
|---|
| | 402 | |
|---|
| | 403 | Simply deletes the corresponding record from the auth_cookie table. |
|---|
| | 404 | """ |
|---|
| | 405 | if req.authname == 'anonymous': |
|---|
| | 406 | # Not logged in |
|---|
| | 407 | return |
|---|
| | 408 | |
|---|
| | 409 | # While deleting this cookie we also take the opportunity to delete |
|---|
| | 410 | # cookies older than 30 days |
|---|
| | 411 | db = self.env.get_db_cnx() |
|---|
| | 412 | cursor = db.cursor() |
|---|
| | 413 | cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s", |
|---|
| | 414 | (req.authname, int(time.time()) - 86400 * 30)) |
|---|
| | 415 | db.commit() |
|---|
| | 416 | self._expire_cookie(req) |
|---|
| | 417 | |
|---|