##// END OF EJS Templates
docs update
docs update

File last commit:

r1121:f3f84771 beta
r1123:9472a015 beta
Show More
login.py
150 lines | 5.4 KiB | text/x-python | PythonLexer
updated docs on every controller
r861 # -*- coding: utf-8 -*-
"""
rhodecode.controllers.login
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Login controller for rhodeocode
:created_on: Apr 22, 2010
:author: marcink
fixed copyright year to 2011
r902 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
updated docs on every controller
r861 :license: GPLv3, see COPYING for more details.
"""
renamed project to rhodecode
r547 # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License or (at your opinion) any later version of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
updated docs on every controller
r861 import logging
import formencode
renamed project to rhodecode
r547 from formencode import htmlfill
updated docs on every controller
r861
from pylons.i18n.translation import _
from pylons.controllers.util import abort, redirect
renamed project to rhodecode
r547 from pylons import request, response, session, tmpl_context as c, url
updated docs on every controller
r861
import rhodecode.lib.helpers as h
renamed project to rhodecode
r547 from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator
from rhodecode.lib.base import BaseController, render
from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
Code refactoring,models renames...
r629 from rhodecode.model.user import UserModel
updated docs on every controller
r861
renamed project to rhodecode
r547
log = logging.getLogger(__name__)
class LoginController(BaseController):
def __before__(self):
super(LoginController, self).__before__()
def index(self):
#redirect if already logged in
c.came_from = request.GET.get('came_from', None)
Fixes for raw_id, needed for git...
r636
replaced all global calls to template context (rhodecode_user), into instance attributes
r1121 if self.rhodecode_user.is_authenticated \
and self.rhodecode_user.username != 'default':
#49 Enabled anonymous access for web interface controllable from permissions pannel
r673
Fixes for raw_id, needed for git...
r636 return redirect(url('home'))
renamed project to rhodecode
r547 if request.POST:
#import Login Form validator class
login_form = LoginForm()
try:
c.form_result = login_form.to_python(dict(request.POST))
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 #form checks for username/password, now we're authenticated
renamed project to rhodecode
r547 username = c.form_result['username']
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 user = UserModel().get_by_username(username,
case_insensitive=True)
auth_user = AuthUser(user.user_id)
auth_user.set_authenticated()
renamed hg_app to rhodecode
r548 session['rhodecode_user'] = auth_user
renamed project to rhodecode
r547 session.save()
Fixes for raw_id, needed for git...
r636
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 log.info('user %s is now authenticated and stored in session',
username)
renamed project to rhodecode
r547 user.update_lastlogin()
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 if c.came_from:
return redirect(c.came_from)
else:
Fixes for raw_id, needed for git...
r636 return redirect(url('home'))
refactor codes and setup for python 2.5...
r564 except formencode.Invalid, errors:
renamed project to rhodecode
r547 return htmlfill.render(
render('/login.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 return render('/login.html')
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate',
'hg.register.manual_activate')
def register(self):
user_model = UserModel()
c.auto_active = False
Code refactoring,models renames...
r629 for perm in user_model.get_by_username('default', cache=False).user_perms:
renamed project to rhodecode
r547 if perm.permission.permission_name == 'hg.register.auto_activate':
c.auto_active = True
break
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 if request.POST:
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 register_form = RegisterForm()()
try:
form_result = register_form.to_python(dict(request.POST))
form_result['active'] = c.auto_active
user_model.create_registration(form_result)
more renames for rhode code !!
r549 h.flash(_('You have successfully registered into rhodecode'),
Fixes for raw_id, needed for git...
r636 category='success')
renamed project to rhodecode
r547 return redirect(url('login_home'))
Fixes for raw_id, needed for git...
r636
refactor codes and setup for python 2.5...
r564 except formencode.Invalid, errors:
renamed project to rhodecode
r547 return htmlfill.render(
render('/register.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 return render('/register.html')
def password_reset(self):
user_model = UserModel()
if request.POST:
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 password_reset_form = PasswordResetForm()()
try:
form_result = password_reset_form.to_python(dict(request.POST))
user_model.reset_password(form_result)
h.flash(_('Your new password was sent'),
Fixes for raw_id, needed for git...
r636 category='success')
renamed project to rhodecode
r547 return redirect(url('login_home'))
Fixes for raw_id, needed for git...
r636
refactor codes and setup for python 2.5...
r564 except formencode.Invalid, errors:
renamed project to rhodecode
r547 return htmlfill.render(
render('/password_reset.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 return render('/password_reset.html')
Fixes for raw_id, needed for git...
r636
renamed project to rhodecode
r547 def logout(self):
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 del session['rhodecode_user']
renamed project to rhodecode
r547 session.save()
log.info('Logging out and setting user as Empty')
Fixes for raw_id, needed for git...
r636 redirect(url('home'))