login: removed log_session model, and replaced it with two lines of code.

- also remove usage of template context
- having dedicated model for this operation wasn't really required.
This commit is contained in:
Marcin Kuzminski 2017-01-13 14:04:44 +01:00
parent 266f9e7ec4
commit 5bab4b8a0c
2 changed files with 6 additions and 47 deletions

View file

@ -39,7 +39,6 @@ from rhodecode.lib.exceptions import UserCreationError
from rhodecode.lib.utils2 import safe_str
from rhodecode.model.db import User
from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
from rhodecode.model.login_session import LoginSession
from rhodecode.model.meta import Session
from rhodecode.model.settings import SettingsModel
from rhodecode.model.user import UserModel
@ -158,11 +157,11 @@ class LoginView(object):
renderer='rhodecode:templates/login.mako')
def login_post(self):
came_from = get_came_from(self.request)
session = self.request.session
login_form = LoginForm()()
try:
session.invalidate()
self.session.invalidate()
form_result = login_form.to_python(self.request.params)
# form checks for username/password, now we're authenticated
headers = _store_user_in_session(
@ -187,13 +186,15 @@ class LoginView(object):
# the fly can throw this exception signaling that there's issue
# with user creation, explanation should be provided in
# Exception itself
session.flash(e, queue='error')
self.session.flash(e, queue='error')
return self._get_template_context()
@CSRFRequired()
@view_config(route_name='logout', request_method='POST')
def logout(self):
LoginSession().destroy_user_session()
user = self.request.user
log.info('Deleting session for user: `%s`', user)
self.session.delete()
return HTTPFound(url('home'))
@HasPermissionAnyDecorator(

View file

@ -1,42 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2017 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# 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 Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Login and cookies session model for RhodeCode
"""
import logging
from pylons import session, tmpl_context as c
from rhodecode.model import BaseModel
log = logging.getLogger(__name__)
class LoginSession(BaseModel):
cls = None
def destroy_user_session(self):
cur_user = c.rhodecode_user
log.info('Deleting session for user: `%s`', cur_user)
session.delete()