daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Apr 26th, 2018 202 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.   def require_login
  36.     login_as_trial_user unless current_user_session
  37.   end
  38.  
  39.   def login_as_trial_user
  40.     name = "anonymous_#{session[:session_id]}"
  41.     if User.find_by_username(name)
  42.       UserSession.create(User.find_by_username(name),true)
  43.     else
  44.       guest_role = User.create(:username => name, :password => name, :password_confirmation => name, :role => "guest", :email => "change@this.com")
  45.       UserSession.create(guest_role, true)
  46.     end
  47.     @current_user_session = UserSession.find
  48.     guest_role
  49.   end
  50.  
  51. 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