From 24c76a7f5d3553e987682d3bb35fe94f8fb4b703 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Mon, 10 Nov 2014 20:20:36 +0100 Subject: [PATCH] login fix --- app/controllers/application_controller.rb | 19 +++++++++++++++++-- app/views/devise/sessions/new.html.erb | 9 +++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 00908b1..7a033b3 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,9 +19,24 @@ if request.referer == sign_in_url super else - stored_location_for(resource) || request.referer || root_path + stored_location_for(resource) || root_path end - end^ + end + rescue_from CanCan::AccessDenied do |exception| + + if user_signed_in? + flash[:error] = "Not authorized to view this page" + session[:user_return_to] = nil + redirect_to root_url + + else + flash[:error] = "You must first login to view this page" + session[:user_return_to] = request.url + redirect_to "/users/sign_in" + end + + end + def get_theme if ThemesForRails.available_theme_names.include?(params[:theme]) params[:theme] diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index bc29165..3bda550 100755 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,5 +1,14 @@

Sign in

<%= notice %>

+

+

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, :autofocus => true %>