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:
parent
fe38e168bd
commit
7826d2f674
2 changed files with 15 additions and 8 deletions
|
@ -31,12 +31,23 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
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')
|
||||
# Attempt to retrieve authenticated user from controller instance or session...
|
||||
if !current_user
|
||||
# No user at all: redirect to login page.
|
||||
session[:user_id] = nil
|
||||
logout
|
||||
session[:return_to] = request.original_url
|
||||
redirect_to_login :alert => I18n.t('application.controller.error_authn')
|
||||
else
|
||||
|
|
|
@ -9,10 +9,7 @@ class SessionsController < ApplicationController
|
|||
def create
|
||||
user = User.authenticate(params[:nick], params[:password])
|
||||
if 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
|
||||
|
||||
login user
|
||||
if session[:return_to].present?
|
||||
redirect_to_url = session[:return_to]
|
||||
session[:return_to] = nil
|
||||
|
@ -27,8 +24,7 @@ class SessionsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
session[:user_id] = nil
|
||||
session[:return_to] = nil
|
||||
logout
|
||||
redirect_to login_url, :notice => I18n.t('sessions.logged_out')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue