daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Mar 16th, 2018 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ApplicationController < ActionController::Base
  2.   helper :all # include all helpers, all the time
  3.   protect_from_forgery # See ActionController::RequestForgeryProtection for details
  4.   #helper_method :current_user, :current_user_session
  5.  
  6.   # Scrub sensitive parameters from your log
  7.   filter_parameter_logging :password
  8.  
  9.   rescue_from CanCan::AccessDenied do |exception|
  10.     flash[:error] = "Access denied."
  11.     redirect_to signup_path
  12.   end
  13.  
  14.   private
  15.   def current_user_session
  16.     return @current_user_session if defined?(@current_user_session)
  17.     @current_user_session = UserSession.find
  18.   end
  19.  
  20.   def current_user
  21.     return @current_user if defined?(@current_user)
  22.     @current_user = current_user_session && current_user_session.user
  23.   end
  24.  
  25.    
  26.   def store_location
  27.     session[:return_to] = request.request_uri
  28.   end
  29.  
  30.   def redirect_back_or_default(default)
  31.     redirect_to(session[:return_to] || default)
  32.     session[:return_to] = nil
  33.   end
  34.  
  35. private
  36.  
  37.   def require_login
  38.     login_as_trial_user unless current_user_session
  39.   end
  40.  
  41.   def login_as_trial_user
  42.     name = "anonymous_#{session[:session_id]}"
  43.     if User.find_by_username(name)
  44.       UserSession.create(User.find_by_username(name),true)
  45.     else
  46.       guest_role = User.create(:username => name, :password => name, :password_confirmation => name, :role => "guest", :email => "change@this.com")
  47.       UserSession.create(guest_role, true)
  48.     end
  49.     @current_user_session = UserSession.find
  50.     guest_role
  51.   end
  52.  
  53. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top