Module: Blocky::Auth
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/blocky/auth.rb
Instance Method Summary collapse
- #blocky_current_user ⇒ Object
- #current_ability ⇒ Object
- #devise_resource_name ⇒ Object
- #login_redirect_path ⇒ Object
- #redirect_back_or_default(default) ⇒ Object
- #store_location ⇒ Object
- #unauthorized(exception) ⇒ Object
Instance Method Details
#blocky_current_user ⇒ Object
12 13 14 |
# File 'app/controllers/concerns/blocky/auth.rb', line 12 def blocky_current_user respond_to?(:current_user) ? current_user : nil end |
#current_ability ⇒ Object
16 17 18 |
# File 'app/controllers/concerns/blocky/auth.rb', line 16 def current_ability @current_ability ||= Blocky::Ability.new(blocky_current_user) end |
#devise_resource_name ⇒ Object
20 21 22 |
# File 'app/controllers/concerns/blocky/auth.rb', line 20 def devise_resource_name Blocky.user_class.underscore.gsub('/', '_') end |
#login_redirect_path ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/concerns/blocky/auth.rb', line 24 def login_redirect_path # Try to use Devise's new session path or use the app's root path devise_new_session_path = "new_#{devise_resource_name}_session_path" if main_app.respond_to?(devise_new_session_path) main_app.send(devise_new_session_path) else main_app.root_path end end |
#redirect_back_or_default(default) ⇒ Object
34 35 36 37 |
# File 'app/controllers/concerns/blocky/auth.rb', line 34 def redirect_back_or_default(default) redirect_to(session["#{devise_resource_name}_return_to"] || default) session["#{devise_resource_name}_return_to"] = nil end |
#store_location ⇒ Object
39 40 41 |
# File 'app/controllers/concerns/blocky/auth.rb', line 39 def store_location session["#{devise_resource_name}_return_to"] = request.fullpath.gsub('//', '/') end |
#unauthorized(exception) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/controllers/concerns/blocky/auth.rb', line 43 def (exception) if blocky_current_user redirect_to main_app.root_url, alert: exception. else store_location redirect_to login_redirect_path, alert: exception. end end |