Trac is being migrated to new services! Issues can be found in our new
YouTrack instance and WIKI pages can be found on our
website.
LocalTracChanges: acct_mgr_plugin_ssl_remember_me_rev_4111.patch
| File acct_mgr_plugin_ssl_remember_me_rev_4111.patch, 9.1 KB (added by datallah, 15 years ago) |
|
AccountManager? rev. 4111 patch to implement SSL login and admin screens and persistent sessions
|
-
|
|
|
|
| 13 | 13 | import os |
| 14 | 14 | import random |
| 15 | 15 | import string |
| | 16 | |
| | 17 | |
| | 18 | |
| 16 | 19 | |
| 17 | 20 | from trac import perm, util |
| 18 | 21 | from trac.core import * |
| 19 | 22 | from trac.config import IntOption |
| 20 | 23 | from trac.notification import NotificationSystem, NotifyEmail |
| 21 | 24 | from trac.prefs import IPreferencePanelProvider |
| | 25 | |
| 22 | 26 | from trac.web import auth |
| 23 | 27 | from trac.web.api import IAuthenticator |
| 24 | 28 | from trac.web.main import IRequestHandler, IRequestFilter |
| … |
… |
|
| 53 | 57 | if password != req.args.get('password_confirm'): |
| 54 | 58 | raise TracError('The passwords must match.') |
| 55 | 59 | |
| | 60 | |
| | 61 | |
| | 62 | |
| 56 | 63 | mgr.set_password(user, password) |
| 57 | 64 | |
| 58 | 65 | db = env.get_db_cnx() |
| … |
… |
|
| 157 | 164 | 'store does not support writing.') |
| 158 | 165 | return writable |
| 159 | 166 | |
| | 167 | |
| | 168 | |
| | 169 | |
| | 170 | |
| | 171 | |
| | 172 | |
| | 173 | |
| | 174 | |
| | 175 | |
| | 176 | |
| | 177 | |
| | 178 | |
| | 179 | |
| | 180 | |
| | 181 | |
| | 182 | |
| | 183 | |
| | 184 | |
| | 185 | |
| 160 | 186 | #IPreferencePanelProvider methods |
| 161 | 187 | def get_preference_panels(self, req): |
| 162 | 188 | if not self._write_check(): |
| … |
… |
|
| 179 | 205 | |
| 180 | 206 | # IRequestFilter methods |
| 181 | 207 | def pre_process_request(self, req, handler): |
| | 208 | |
| | 209 | |
| | 210 | |
| | 211 | |
| | 212 | |
| | 213 | |
| | 214 | |
| | 215 | |
| | 216 | |
| | 217 | |
| | 218 | |
| | 219 | |
| | 220 | |
| | 221 | |
| | 222 | |
| | 223 | |
| | 224 | |
| 182 | 225 | return handler |
| 183 | 226 | |
| 184 | 227 | def post_process_request(self, req, template, data, content_type): |
| … |
… |
|
| 377 | 420 | except TracError, e: |
| 378 | 421 | data['registration_error'] = e.message |
| 379 | 422 | else: |
| 380 | | req.redirect(req.href.login()) |
| | 423 | redirect_url = None |
| | 424 | referer = req.args.get('referer') |
| | 425 | if referer: |
| | 426 | redirect_url = "%s?referer=%s" % (req.href.login(), referer) |
| | 427 | req.redirect(redirect_url or req.href.login()) |
| 381 | 428 | data['reset_password_enabled'] = \ |
| 382 | 429 | (self.env.is_component_enabled(AccountModule) |
| 383 | 430 | and NotificationSystem(self.env).smtp_enabled) |
| … |
… |
|
| 422 | 469 | match_request = if_enabled(auth.LoginModule.match_request) |
| 423 | 470 | |
| 424 | 471 | def process_request(self, req): |
| 425 | | if req.path_info.startswith('/login') and req.authname == 'anonymous': |
| | 472 | if req.path_info.startswith('/login') and : |
| 426 | 473 | data = { |
| 427 | 474 | 'referer': self._referer(req), |
| 428 | 475 | 'reset_password_enabled': AccountModule(self.env).reset_password_enabled |
| … |
… |
|
| 432 | 479 | return 'login.html', data, None |
| 433 | 480 | return auth.LoginModule.process_request(self, req) |
| 434 | 481 | |
| | 482 | |
| | 483 | |
| | 484 | |
| | 485 | |
| | 486 | |
| | 487 | |
| | 488 | |
| | 489 | |
| | 490 | |
| | 491 | |
| | 492 | |
| | 493 | |
| | 494 | |
| | 495 | |
| | 496 | |
| | 497 | |
| 435 | 498 | def _do_login(self, req): |
| 436 | 499 | if not req.remote_user: |
| 437 | 500 | req.redirect(self.env.abs_href()) |
| 438 | | return auth.LoginModule._do_login(self, req) |
| | 501 | res = auth.LoginModule._do_login(self, req) |
| | 502 | if req.args.get('rememberme', '0') == '1': |
| | 503 | req.outcookie['trac_auth']['expires'] = 86400 * 30 |
| | 504 | req.outcookie['trac_auth_session'] = '1' |
| | 505 | req.outcookie['trac_auth_session']['path'] = self.env.href() |
| | 506 | return res |
| 439 | 507 | |
| | 508 | |
| | 509 | |
| | 510 | |
| | 511 | |
| | 512 | |
| | 513 | |
| | 514 | |
| | 515 | |
| | 516 | |
| | 517 | |
| | 518 | |
| | 519 | |
| | 520 | |
| | 521 | |
| | 522 | |
| | 523 | |
| | 524 | |
| | 525 | |
| 440 | 526 | def _remote_user(self, req): |
| 441 | 527 | user = req.args.get('user') |
| 442 | 528 | password = req.args.get('password') |
| … |
… |
|
| 449 | 535 | def _redirect_back(self, req): |
| 450 | 536 | """Redirect the user back to the URL she came from.""" |
| 451 | 537 | referer = self._referer(req) |
| 452 | | if referer and not referer.startswith(req.base_url): |
| 453 | | # don't redirect to external sites |
| 454 | | referer = None |
| | 538 | if referer: |
| | 539 | u = urlparse.urlparse(referer) |
| | 540 | r = urlparse.urlparse(req.base_url) |
| | 541 | if u[1] and u[1] != r[1]: |
| | 542 | # don't redirect to external sites |
| | 543 | referer = None |
| 455 | 544 | req.redirect(referer or self.env.abs_href()) |
| 456 | 545 | |
| 457 | 546 | def _referer(self, req): |
| … |
… |
|
| 576 | 665 | def _send_email(self, req): |
| 577 | 666 | notifier = EmailVerificationNotification(self.env) |
| 578 | 667 | notifier.notify(req.authname, req.session['email_verification_token']) |
| | 668 | |
-
|
|
|
|
| 24 | 24 | </div> |
| 25 | 25 | |
| 26 | 26 | <form method="post" id="acctmgr_registerform" action=""> |
| | 27 | |
| 27 | 28 | <fieldset> |
| 28 | 29 | <legend>Required</legend> |
| 29 | 30 | <div> |
| … |
… |
|
| 43 | 44 | class="textwidget" size="20" /> |
| 44 | 45 | </label> |
| 45 | 46 | </div> |
| 46 | | </fieldset> |
| 47 | | <fieldset> |
| 48 | | <legend>Optional</legend> |
| 49 | 47 | <div> |
| 50 | 48 | <label>Name: |
| 51 | 49 | <input type="text" name="name" class="textwidget" size="20" /> |
-
|
|
|
|
| 28 | 28 | <input type="hidden" name="referer" value="${referer}" /> |
| 29 | 29 | <div> |
| 30 | 30 | <label for="user">Username:</label> |
| 31 | | <input type="text" id="user" name="user" class="textwidget" size="20" /> |
| | 31 | <input type="text" id="user" name="user" class="textwidget" size="20" /> |
| 32 | 32 | </div> |
| 33 | 33 | <div> |
| 34 | 34 | <label for="password">Password:</label> |
| 35 | 35 | <input type="password" id="password" name="password" class="textwidget" size="20" /> |
| 36 | 36 | </div> |
| | 37 | |
| | 38 | |
| | 39 | |
| | 40 | |
| 37 | 41 | <input type="submit" value="Login" /> |
| 38 | 42 | |
| 39 | 43 | <p py:if="reset_password_enabled"> |
Download in other formats:
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!