Changeset 3731

Show
Ignore:
Timestamp:
05/28/08 01:02:59 (6 months ago)
Author:
pacopablo
Message:

Added forcing password change after reset. Patch by s0undt3ch. Minor change such that the message indicating password reset needed isn't shown after a successful password reset. Fixes #1427

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • accountmanagerplugin/trunk/acct_mgr/admin.py

    r2533 r3731  
    5858                    self.config.set(option.section, option.name, newvalue) 
    5959                    self.config.save() 
     60            self.config.set('account-manager', 'force_passwd_change', 
     61                            req.args.get('force_passwd_change')) 
     62            self.config.save() 
     63 
     64 
    6065        try: 
    6166            selected = self.account_manager.password_store 
     
    7681        ] 
    7782        sections = sorted(sections, key=lambda i: i['name']) 
    78         return 'admin_accountsconfig.html', {'sections': sections} 
     83        data = {'sections': sections, 
     84                'force_passwd_change': self.account_manager.force_passwd_change} 
     85        return 'admin_accountsconfig.html', data 
    7986 
    8087    def _do_users(self, req): 
     
    136143 
    137144    # ITemplateProvider 
    138       
     145 
    139146    def get_htdocs_dirs(self): 
    140147        """Return the absolute path of a directory containing additional 
     
    142149        """ 
    143150        return [] 
    144   
     151 
    145152    def get_templates_dirs(self): 
    146153        """Return the absolute path of the directory containing the provided 
  • accountmanagerplugin/trunk/acct_mgr/api.py

    r3728 r3731  
    1111 
    1212from trac.core import * 
    13 from trac.config import Option, ExtensionOption 
     13from trac.config import Option, BoolOption, ExtensionOption 
    1414 
    1515class IPasswordStore(Interface): 
     
    8686    stores = ExtensionPoint(IPasswordStore) 
    8787    change_listeners = ExtensionPoint(IAccountChangeListener) 
     88    force_passwd_change = BoolOption('account-manager', 'force_passwd_change', 
     89                                     True, doc="Forge the user to change " 
     90                                     "password when it's reset.") 
    8891 
    8992    # Public API 
  • accountmanagerplugin/trunk/acct_mgr/templates/admin_accountsconfig.html

    r1524 r3731  
    3030        </div> 
    3131      </fieldset> 
     32      <fieldset> 
     33        <legend>Password Reset</legend> 
     34        <label for="force_passwd_change"> 
     35          Force users to change passwords after a password reset? 
     36        </label> 
     37        <input type="radio" name="force_passwd_change" value="true" 
     38          checked="${force_passwd_change and 'checked' or None}">Yes</input> 
     39        <input type="radio" name="force_passwd_change" value="false" 
     40          checked="${not force_passwd_change and 'checked' or None}">No</input> 
     41      </fieldset> 
    3242      <div class="buttons"> 
    3343        <input type="submit" name="save" value="Save" /> 
  • accountmanagerplugin/trunk/acct_mgr/templates/prefs_account.html

    r1709 r3731  
    3535    </py:if> 
    3636  </div> 
    37   
     37 
    3838  <head> 
    3939    <title>Account</title> 
     
    4545      <p>$account.error</p> 
    4646    </div> 
    47  
     47    <div class="system-message" py:if="account.force_change_passwd"> 
     48      <h2>Immediate action required</h2> 
     49      <p>You are required to change password because of a recent 
     50        password change request.</p> 
     51      <p><strong>Please change your password now.</strong></p> 
     52    </div> 
    4853    <p py:if="account.message">$account.message</p> 
    4954    <h2>Change Password</h2> 
  • accountmanagerplugin/trunk/acct_mgr/web_ui.py

    r3554 r3731  
    2020from trac.web import auth 
    2121from trac.web.api import IAuthenticator 
    22 from trac.web.main import IRequestHandler 
     22from trac.web.main import IRequestHandler, IRequestFilter 
    2323from trac.web.chrome import INavigationContributor, ITemplateProvider 
    24 from trac.util import Markup 
     24from genshi.builder import tag 
    2525 
    2626from api import AccountManager 
     
    120120    """ 
    121121 
    122     implements(IPreferencePanelProvider, IRequestHandler, ITemplateProvider, INavigationContributor) 
     122    implements(IPreferencePanelProvider, IRequestHandler, ITemplateProvider, 
     123               INavigationContributor, IRequestFilter) 
    123124 
    124125    _password_chars = string.ascii_letters + string.digits 
    125     password_length = IntOption('account-manager', 'generated_password_length', 8, 
    126                                 'Length of the randomly-generated passwords ' 
     126    password_length = IntOption('account-manager', 'generated_password_length', 
     127                                8, 'Length of the randomly-generated passwords ' 
    127128                                'created when resetting the password for an ' 
    128129                                'account.') 
     
    158159        return 'reset_password.html', data, None 
    159160 
     161    # IRequestFilter methods 
     162    def pre_process_request(self, req, handler): 
     163        return handler 
     164 
     165    def post_process_request(self, req, template, data, content_type): 
     166        if req.authname and req.authname != 'anonymous': 
     167            if req.session.get('force_change_passwd', False): 
     168                redirect_url = req.href.prefs('account') 
     169                if req.path_info != redirect_url: 
     170                    req.redirect(redirect_url) 
     171        return (template, data, content_type) 
     172 
    160173    # INavigationContributor methods 
    161174    def get_active_navigation_item(self, req): 
     
    166179            return 
    167180        if req.authname == 'anonymous': 
    168             yield 'metanav', 'reset_password', Markup('<a href="%s">Forgot your password?</a>') % req.href.reset_password() 
     181            yield 'metanav', 'reset_password', tag.a( 
     182                "Forgot your password?", href=req.href.reset_password()) 
    169183 
    170184    def reset_password_enabled(self): 
     
    180194        delete_enabled = AccountManager(self.env).supports('delete_user') 
    181195        data = {'delete_enabled': delete_enabled} 
     196        force_change_password = req.session.get('force_change_passwd', False) 
     197        if force_change_password: 
     198            data['force_change_passwd'] = True 
    182199        if req.method == 'POST': 
    183200            if action == 'save': 
    184201                data.update(self._do_change_password(req)) 
     202                if force_change_password: 
     203                    data['force_change_passwd'] = False 
     204                    del(req.session['force_change_passwd']) 
     205                    req.session.save() 
    185206            elif action == 'delete' and delete_enabled: 
    186207                data.update(self._do_delete(req)) 
     
    209230        new_password = self._random_password() 
    210231        notifier.notify(username, new_password) 
    211         AccountManager(self.env).set_password(username, new_password) 
     232        mgr = AccountManager(self.env) 
     233        mgr.set_password(username, new_password) 
     234        if mgr.force_passwd_change: 
     235            db = self.env.get_db_cnx() 
     236            cursor = db.cursor() 
     237            cursor.execute("UPDATE session_attribute SET value=%s " 
     238                           "WHERE name=%s AND sid=%s AND authenticated=1", 
     239                           (1, "force_change_passwd", username)) 
     240            if not cursor.rowcount: 
     241                cursor.execute("INSERT INTO session_attribute " 
     242                               "(sid,authenticated,name,value) " 
     243                               "VALUES (%s,1,%s,%s)", 
     244                               (username, "force_change_passwd", 1)) 
     245            db.commit() 
     246 
    212247        return {'sent_to_email': email} 
    213248 
     
    250285 
    251286    # ITemplateProvider 
    252      
     287 
    253288    def get_htdocs_dirs(self): 
    254289        """Return the absolute path of a directory containing additional 
     
    298333            return 
    299334        if req.authname == 'anonymous': 
    300             yield 'metanav', 'register', Markup('<a href="%s">Register</a>') % req.href.register() 
     335            yield 'metanav', 'register', tag.a("Register", 
     336                                               href=req.href.register()) 
     337 
    301338 
    302339    # IRequestHandler methods 
     
    325362 
    326363    # ITemplateProvider 
    327      
     364 
    328365    def get_htdocs_dirs(self): 
    329366        """Return the absolute path of a directory containing additional 
     
    402439 
    403440    # ITemplateProvider 
    404      
     441 
    405442    def get_htdocs_dirs(self): 
    406443        """Return the absolute path of a directory containing additional