2012-09-23 02:39:12 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
protect_from_forgery
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
# this is for global login
|
|
|
|
include ContentHelper
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
helper_method :user
|
|
|
|
helper_method :authenticated?
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
after_filter :store_location
|
|
|
|
|
|
|
|
def store_location
|
|
|
|
# store last url - this is needed for post-login redirect to whatever the user last visited.
|
|
|
|
if (!request.fullpath.match("/users/") && !request.xhr?) # don't store ajax calls
|
|
|
|
session[:previous_url] = request.fullpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_sign_in_path_for(resource)
|
|
|
|
session[:previous_url] || root_path
|
|
|
|
end
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def require_no_user
|
|
|
|
if authenticated?
|
|
|
|
flash[:warning] = "You must be logged out."
|
2012-10-29 18:21:36 +00:00
|
|
|
store and redirect_to edit_user_path(user)
|
2012-09-23 02:39:12 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_user
|
|
|
|
unless authenticated?
|
|
|
|
flash[:warning] = "You must be logged in."
|
2012-09-24 01:38:26 +00:00
|
|
|
store and redirect_to new_session_path
|
2012-09-23 02:39:12 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user
|
|
|
|
current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def authenticated?
|
|
|
|
current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|