Fixed return_to when authorization gets lost.

This commit is contained in:
benni 2012-12-30 16:34:01 +01:00
parent f6ff422405
commit 0364562273
2 changed files with 9 additions and 3 deletions

View file

@ -22,7 +22,7 @@ class ApplicationController < ActionController::Base
helper_method :current_user helper_method :current_user
def deny_access def deny_access
self.return_to = request.original_url session[:return_to] = request.original_url
redirect_to login_url, :alert => 'Access denied!' redirect_to login_url, :alert => 'Access denied!'
end end
@ -33,7 +33,7 @@ class ApplicationController < ActionController::Base
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 session[:user_id] = nil
session['return_to'] = request.fullpath session[:return_to] = request.original_url
redirect_to login_url, :alert => 'Authentication required!' redirect_to login_url, :alert => 'Authentication required!'
else else
# We have an authenticated user, now check role... # We have an authenticated user, now check role...

View file

@ -11,7 +11,13 @@ class SessionsController < ApplicationController
if user if user
session[:user_id] = user.id session[:user_id] = user.id
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
redirect_to session['return_to'] || root_url, :notice => "Logged in!" if session[:return_to].present?
redirect_to_url = session[:return_to]
session[:return_to] = nil
else
redirect_to_url = root_url
end
redirect_to redirect_to_url, :notice => "Logged in!"
else else
flash.now.alert = "Invalid email or password" flash.now.alert = "Invalid email or password"
render "new" render "new"