Changeset 2154

Show
Ignore:
Timestamp:
04/02/07 05:15:48 (2 years ago)
Author:
wkornew
Message:

DbAuthPlugin:

Updated to Trac 0.11. Changing the password is not possible (I'll have to add an extension to the new prefs interface in Trac 0.11).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dbauthplugin/simple

    • Property svn:externals deleted
  • dbauthplugin/simple/dbauth/auth.py

    r1729 r2154  
    1 # -*- coding: iso8859-1 -*- 
     1# -*- coding: utf-8 -*- 
    22# 
    3 # Copyright (C) 2003-2005 Edgewall Software 
    4 # Copyright (C) 2003-2005 Jonas Borgström <jonas@edgewall.com> 
    5 # Copyright (C) 2006 Brad Anderson <brad@dsource.org> 
    6 # Copyright (C) 2006 Waldemar Kornewald <wkornewald@gmx.net> 
    7 # All rights reserved. 
    8 
    9 # This software is licensed as described in the file COPYING, which 
    10 # you should have received as part of this distribution. The terms 
    11 # are also available at http://trac.edgewall.com/license.html. 
    12 
    13 # This software consists of voluntary contributions made by many 
    14 # individuals. For the exact contribution history, see the revision 
    15 # history and logs, available at http://projects.edgewall.com/trac/. 
    16 
    17 # Authors: Brad Anderson <brad@dsource.org> 
    18 #          Waldemar Kornewald <wkornewald@gmx.net> 
     3# Copyright 2007 Waldemar Kornewald 
     4# All rights reserved. Distributed under the terms of the MIT license. 
    195 
    206import re 
     
    2612from trac.config import * 
    2713from trac.db import * 
    28 from trac.web.api import IAuthenticator, IRequestHandler 
     14from trac.web.api import IAuthenticator 
     15from trac.web.main import IRequestHandler 
    2916from trac.web.chrome import INavigationContributor, ITemplateProvider 
    30 from trac.util import escape, hex_entropy, TracError, Markup 
     17from trac.util import escape, hex_entropy, Markup 
    3118 
    3219 
     
    9885                yield 'metanav', 'password', \ 
    9986                    Markup('<a href="%s">Password</a>' \ 
    100                             % escape(req.href.password())) 
     87                            % req.href.password()) 
    10188            yield 'metanav', 'logout', Markup('<b><a href="%s">Logout</a></b>' \ 
    102                   % escape(req.href.logout())) 
     89                  % req.href.logout()) 
    10390        else: 
    10491            yield 'metanav', 'login', Markup('<b><a href="%s">Login</a></b>' \ 
    105                   % escape(req.href.login())) 
     92                  % req.href.login()) 
    10693 
    10794    # IRequestHandler methods 
     
    114101 
    115102    def process_request(self, req): 
     103        referer = req.args.get('referer') or req.get_header('Referer') 
     104        if not referer or referer.endswith('/login') or \ 
     105                referer.endswith('/settings') or len(referer) == 0: 
     106            referer = req.href() 
     107 
     108        data = {'referer': referer} 
     109 
    116110        if req.method == 'POST': 
    117111            if req.args.get('login'): 
    118                 uid, pwd = req.args.get('uid').lower(), req.args.get('pwd') 
    119                 referer = req.args.get('referer') 
    120                 if not referer or len(referer) == 0: 
    121                     referer = req.href() 
     112                uid, pwd = req.args.get('user').lower(), req.args.get('password') 
    122113                if self._check_login(uid, pwd): 
    123114                    self._do_login(req, uid) 
    124115                    req.redirect(referer) 
    125116                else: 
    126                     req.hdf['auth.message'] = 'Login Incorrect' 
    127                     req.hdf['referer'] = referer 
    128             elif req.args.get('password'): 
    129                 old, new, repeat = req.args.get('opwd'), req.args.get('npwd'), req.args.get('rpwd') 
    130                 if not new or len(new) < 5: 
    131                     req.hdf['auth.message'] = 'New password too short' 
    132                 elif new != repeat: 
    133                     req.hdf['auth.message'] = 'Repeated password does not match' 
    134                 elif not self._check_login(req.authname, old): 
    135                     req.hdf['auth.message'] = 'Wrong Password' 
    136                 else: 
    137                     req.hdf['auth.message'] = 'Password Changed' 
    138                     self._change_password(req, new) 
    139  
    140         referer = req.args.get('referer') or req.get_header('Referer') 
    141         if not referer or referer.endswith('/login') or \ 
    142                 referer.endswith('/settings') or len(referer) == 0: 
    143             referer = req.href() 
     117                    data['login_error'] = 'Wrong username or password. Please try again.' 
     118            else: 
     119                data['login_error'] = 'Could not understand your command. Did you really use this web form?' 
    144120 
    145121        if req.path_info.startswith('/login'): 
    146             req.hdf['referer'] = referer 
    147             template = "login.cs" 
    148         elif req.path_info.startswith('/password'): 
    149             template = 'password.cs' 
     122            template = "login.html" 
    150123        elif req.path_info.startswith('/logout'): 
    151124            self._do_logout(req) 
    152125            req.redirect(referer) 
    153         return template, None 
     126        return template, data, None 
    154127 
    155128    # ITemplateProvider methods 
    156129 
    157130    def get_htdocs_dirs(self): 
    158         """Return the absolute path of a directory containing additional 
    159         static resources (such as images, style sheets, etc). 
    160         """ 
    161         from pkg_resources import resource_filename 
    162         return [('dbauth', resource_filename(__name__, 'htdocs'))] 
    163      
     131        return [] 
     132 
    164133    def get_templates_dirs(self): 
    165         """Return the absolute path of the directory containing the provided 
    166         ClearSilver templates. 
    167         """ 
    168134        from pkg_resources import resource_filename 
    169135        return [resource_filename(__name__, 'templates')] 
     
    285251                       (user, email)) 
    286252        db.commit() 
    287  
    288     def _change_password(self, req, newpwd): 
    289         if req.authname == 'anonymous': 
    290             # Not logged in 
    291             return 
    292  
    293         # change the password 
    294         newpwd = self.crypt.new(newpwd).hexdigest() 
    295         db = get_db(self.env) 
    296         cursor = db.cursor() 
    297         sql = "UPDATE %s SET %s = %%s WHERE LOWER(%s) = LOWER(%%s)" % \ 
    298               (self.users['table'], self.users['password'], 
    299                self.users['username']) 
    300         cursor.execute(sql, (newpwd, req.authname)) 
    301         db.commit() 
  • dbauthplugin/simple/setup.cfg

    r819 r2154  
    11[egg_info] 
    22tag_build = dev 
    3 tag_svn_revision = fals
     3tag_svn_revision = tru
  • dbauthplugin/simple/setup.py

    r1488 r2154  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
    3 # 
    43 
    54from setuptools import setup, find_packages 
    65 
    7 PACKAGE = 'TracDbAuth' 
    8 VERSION = '0.4' 
     6setup( 
     7    name = 'TracDbAuth', 
     8    version = '0.4', 
     9    description = 'DB-based authentication for Trac', 
     10    license = 'MIT', 
     11    author = 'Waldemar Kornewald', 
     12    url = 'http://haiku-os.org', 
    913 
    10 setup( 
    11     name=PACKAGE, version=VERSION, 
    12     description='Trac DB auth plugin', 
    13     author="Waldemar Kornewald", author_email="wkornewald@gmx.net", 
    14     license='BSD', url='http://haiku-os.org', 
    15     packages=find_packages(exclude=['ez_setup', '*.tests*']), 
    16     package_data={ 
     14    packages = find_packages(exclude=['ez_setup', '*.tests*']), 
     15    package_data = { 
    1716        'dbauth': [ 
    1817            'htdocs/css/*.css', 
    1918            'htdocs/img/*.png', 
    2019            'htdocs/js/*.js', 
    21             'templates/*.cs' 
     20            'templates/*.html', 
     21            'templates/*.txt' 
    2222        ] 
    2323    },