Changeset - 7109d15c6813
[Not reviewed]
default
0 3 0
Marcin Kuzminski - 15 years ago 2010-05-22 16:07:28
marcin@python-works.com
cleared prints leftoovers, and changed current user fetching in login controller
3 files changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/login.py
Show inline comments
 
@@ -3,25 +3,26 @@ from formencode import htmlfill
 
from pylons import request, response, session, tmpl_context as c, url
 
from pylons.controllers.util import abort, redirect
 
from pylons_app.lib.base import BaseController, render
 
import formencode
 
from pylons_app.model.forms import LoginForm
 
from pylons_app.lib.auth import AuthUser
 

	
 
log = logging.getLogger(__name__)
 

	
 
class LoginController(BaseController):
 

	
 
    def index(self):
 
        if session.get('hg_app_user', AuthUser()).is_authenticated:
 
        #redirect if already logged in
 
        if c.hg_app_user.is_authenticated:
 
            return redirect(url('hg_home'))
 
        
 
        if request.POST:
 
            #import Login Form validator class
 
            login_form = LoginForm()
 
            try:
 
                c.form_result = login_form.to_python(dict(request.POST))
 
                return redirect(url('hg_home'))
 
                               
 
            except formencode.Invalid as errors:
 
                c.form_errors = errors.error_dict
 
                return htmlfill.render(
pylons_app/model/forms.py
Show inline comments
 
@@ -60,25 +60,24 @@ class ValidAuth(formencode.validators.Fa
 
    e_dict = {'username':messages['invalid_login'],
 
              'password':messages['invalid_password']}
 
    
 
    def validate_python(self, value, state):
 
        sa = meta.Session
 
        crypted_passwd = get_crypt_password(value['password'])
 
        username = value['username']
 
        try:
 
            user = sa.query(Users).filter(Users.username == username).one()
 
        except (NoResultFound, MultipleResultsFound, OperationalError) as e:
 
            log.error(e)
 
            user = None
 
        print value
 
        if user:
 
            if user.active:
 
                if user.username == username and user.password == crypted_passwd:
 
                    log.info('user %s authenticated correctly', username)
 
                    from pylons_app.lib.auth import AuthUser
 
                    auth_user = AuthUser()
 
                    auth_user.username = username
 
                    auth_user.is_authenticated = True
 
                    auth_user.is_admin = user.admin
 
                    session['hg_app_user'] = auth_user
 
                    session.save()
 
                    return value
pylons_app/model/hg_model.py
Show inline comments
 
@@ -3,28 +3,29 @@
 
#
 
# Copyright (c) 2010 marcink.  All rights reserved.
 
#
 
from vcs.exceptions import RepositoryError
 
'''
 
Created on Apr 9, 2010
 

	
 
@author: marcink
 
'''
 
import os
 
from pylons import tmpl_context as c, app_globals as g, session, request, config
 
from pylons.controllers.util import abort
 
import sys
 
try:
 
    from vcs.backends.hg import get_repositories, MercurialRepository
 
except ImportError:
 
    print 'You have to import vcs module'
 
    sys.stderr.write('You have to import vcs module')
 
    raise Exception('Unable to import vcs')
 

	
 
class HgModel(object):
 
    """
 
    Mercurial Model
 
    """
 

	
 

	
 
    def __init__(self):
 
        """
 
        Constructor
 
        """
0 comments (0 inline, 0 general)