Module: Authentication
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/authentication.rb
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #auth_failed ⇒ Object
- #current_user ⇒ Object
- #require_user ⇒ Object
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in! ⇒ Object
- #signed_in? ⇒ Boolean
- #signed_in_path(source) ⇒ Object
- #signed_out! ⇒ Object
- #signed_out? ⇒ Boolean
- #signed_out_path ⇒ Object
- #updated_account_path ⇒ Object
Instance Method Details
#admin? ⇒ Boolean
56 57 58 |
# File 'lib/authentication.rb', line 56 def admin? signed_in? && current_user.role.admin? end |
#auth_failed ⇒ Object
46 47 48 49 50 |
# File 'lib/authentication.rb', line 46 def auth_failed sign_out session[:attempted_path] = request.fullpath redirect_to new_session_path, status: :see_other end |
#current_user ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/authentication.rb', line 12 def current_user if session[:user_id] @current_user ||= User.find(session[:user_id]) end @current_user rescue ActiveRecord::RecordNotFound sign_out nil end |
#require_user ⇒ Object
8 9 10 |
# File 'lib/authentication.rb', line 8 def require_user if signed_in? then true else redirect_to(root_path) end end |
#sign_in(user) ⇒ Object
23 24 25 26 |
# File 'lib/authentication.rb', line 23 def sign_in user session[:user_id] = user.id @current_user = user end |
#sign_out ⇒ Object
28 29 30 31 |
# File 'lib/authentication.rb', line 28 def sign_out reset_session remove_instance_variable :@current_user if defined?(@current_user) end |
#signed_in! ⇒ Object
41 42 43 44 |
# File 'lib/authentication.rb', line 41 def signed_in! return if signed_in? auth_failed end |
#signed_in? ⇒ Boolean
33 34 35 |
# File 'lib/authentication.rb', line 33 def signed_in? !!current_user end |
#signed_in_path(source) ⇒ Object
60 61 62 |
# File 'lib/authentication.rb', line 60 def signed_in_path source session[:attempted_path] || current_user.role.admin? ? cms_path : root_path end |
#signed_out! ⇒ Object
52 53 54 |
# File 'lib/authentication.rb', line 52 def signed_out! end |
#signed_out? ⇒ Boolean
37 38 39 |
# File 'lib/authentication.rb', line 37 def signed_out? !signed_in? end |
#signed_out_path ⇒ Object
68 69 70 |
# File 'lib/authentication.rb', line 68 def signed_out_path root_path end |
#updated_account_path ⇒ Object
64 65 66 |
# File 'lib/authentication.rb', line 64 def updated_account_path root_path end |