##// END OF EJS Templates
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)

File last commit:

r200:b48ebda8 default
r207:8bdec094 rhodecode-0.0.0.7.1 default
Show More
auth.py
75 lines | 2.3 KiB | text/x-python | PythonLexer
Added LoginRequired decorator, empty User data container, hash functions
r190 from functools import wraps
implemented autentication
r52 from pylons import session, url
from pylons.controllers.util import abort, redirect
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 from pylons_app.model import meta
Changed import to base. Removed action logging from auth to simplehg....
r197 from pylons_app.model.db import Users
Added LoginRequired decorator, empty User data container, hash functions
r190 from sqlalchemy.exc import OperationalError
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
Added LoginRequired decorator, empty User data container, hash functions
r190 import crypt
import logging
log = logging.getLogger(__name__)
Marcin Kuzminski
Added app basic auth....
r41
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 def get_crypt_password(password):
Added LoginRequired decorator, empty User data container, hash functions
r190 """
Cryptographic function used for password hashing
@param password: password to hash
"""
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 return crypt.crypt(password, '6a')
Marcin Kuzminski
Static files for production fixed...
r46
Marcin Kuzminski
Added app basic auth....
r41 def authfunc(environ, username, password):
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 sa = meta.Session
password_crypt = get_crypt_password(password)
try except error on non existing user table
r42 try:
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 user = sa.query(Users).filter(Users.username == username).one()
except (NoResultFound, MultipleResultsFound, OperationalError) as e:
try except error on non existing user table
r42 log.error(e)
Marcin Kuzminski
Changed auth lib for sqlalchemy
r64 user = None
if user:
if user.active:
if user.username == username and user.password == password_crypt:
Marcin Kuzminski
Added app basic auth....
r41 log.info('user %s authenticated correctly', username)
return True
else:
log.error('user %s is disabled', username)
return False
Added LoginRequired decorator, empty User data container, hash functions
r190 class AuthUser(object):
"""
A simple object that handles a mercurial username for authentication
"""
moved checking for user in session to wrapper function of LoginRequired decorator since it was working quite strange.
r199 username = 'None'
Added LoginRequired decorator, empty User data container, hash functions
r190 is_authenticated = False
is_admin = False
permissions = set()
group = set()
def __init__(self):
pass
#===============================================================================
# DECORATORS
#===============================================================================
class LoginRequired(object):
"""
Must be logged in to execute this function else redirect to login page
"""
def __init__(self):
pass
def __call__(self, func):
@wraps(func)
def _wrapper(*fargs, **fkwargs):
moved checking for user in session to wrapper function of LoginRequired decorator since it was working quite strange.
r199 user = session.get('hg_app_user', AuthUser())
log.info('Checking login required for user:%s', user.username)
Added LoginRequired decorator, empty User data container, hash functions
r190 if user.is_authenticated:
log.info('user %s is authenticated', user.username)
func(*fargs)
else:
logging.info('user %s not authenticated', user.username)
moved checking for user in session to wrapper function of LoginRequired decorator since it was working quite strange.
r199 logging.info('redirecting to login page')
Added LoginRequired decorator, empty User data container, hash functions
r190 return redirect(url('login_home'))
implemented autentication
r52
Added LoginRequired decorator, empty User data container, hash functions
r190 return _wrapper