move login and logout to separate methods

Conflicts:
	app/controllers/sessions_controller.rb

Conflicts:
	app/controllers/application_controller.rb
	app/controllers/sessions_controller.rb
This commit is contained in:
wvengen 2013-06-15 02:04:44 +02:00
parent fe38e168bd
commit 7826d2f674
2 changed files with 15 additions and 8 deletions

View file

@ -31,12 +31,23 @@ class ApplicationController < ActionController::Base
end end
private private
def login(user)
session[:user_id] = user.id
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
session[:locale] = user.locale
end
def logout
session[:user_id] = nil
session[:return_to] = nil
end
def authenticate(role = 'any') def authenticate(role = 'any')
# Attempt to retrieve authenticated user from controller instance or session... # Attempt to retrieve authenticated user from controller instance or session...
if !current_user if !current_user
# No user at all: redirect to login page. # No user at all: redirect to login page.
session[:user_id] = nil logout
session[:return_to] = request.original_url session[:return_to] = request.original_url
redirect_to_login :alert => I18n.t('application.controller.error_authn') redirect_to_login :alert => I18n.t('application.controller.error_authn')
else else

View file

@ -9,10 +9,7 @@ class SessionsController < ApplicationController
def create def create
user = User.authenticate(params[:nick], params[:password]) user = User.authenticate(params[:nick], params[:password])
if user if user
session[:user_id] = user.id login user
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
session[:locale] = user.locale
if session[:return_to].present? if session[:return_to].present?
redirect_to_url = session[:return_to] redirect_to_url = session[:return_to]
session[:return_to] = nil session[:return_to] = nil
@ -27,8 +24,7 @@ class SessionsController < ApplicationController
end end
def destroy def destroy
session[:user_id] = nil logout
session[:return_to] = nil
redirect_to login_url, :notice => I18n.t('sessions.logged_out') redirect_to login_url, :notice => I18n.t('sessions.logged_out')
end end