Module: Nyauth::SessionConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- ControllerConcern, Test::ControllerMacros, Test::FeatureMacros
- Defined in:
- app/controllers/concerns/nyauth/session_concern.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #current_authenticated(options = {}) ⇒ Object
-
#require_authentication!(options = {}) ⇒ Object
ex.) before_action -> { require_authentication! as: :user }, only: :secret_action.
-
#sign_in(client) ⇒ Object
ex.) sign_in(client).
-
#sign_out ⇒ Object
ex.) sign_out.
-
#signed_in?(options = {}) ⇒ Boolean
ex.) signed_in?(as: :user).
- #store_signed_in_status(client) ⇒ Object
Instance Method Details
#current_authenticated(options = {}) ⇒ Object
51 52 53 54 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 51 def current_authenticated( = {}) .reverse_merge!(as: :user) nyauth_nyan.session.fetch([:as]) end |
#require_authentication!(options = {}) ⇒ Object
ex.) before_action -> { require_authentication! as: :user }, only: :secret_action
40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 40 def require_authentication!( = {}) .reverse_merge!(as: :user) return if self.class.allow_actions == :all return if self.class.allow_actions.present? && request[:action].to_sym.in?(self.class.allow_actions) unless signed_in?() session["#{options[:as]}_return_to"] = request.url if request.get? redirect_to new_session_path_for([:as]) end end |
#sign_in(client) ⇒ Object
ex.) sign_in(client)
14 15 16 17 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 14 def sign_in(client) return unless client store_signed_in_status(client) end |
#sign_out ⇒ Object
ex.) sign_out
29 30 31 32 33 34 35 36 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 29 def sign_out reset_session if Nyauth.configuration. # ex.) cookies.signed[:user_id] .delete :nyauth_cookie_auth end end |
#signed_in?(options = {}) ⇒ Boolean
ex.) signed_in?(as: :user)
21 22 23 24 25 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 21 def signed_in?( = {}) .reverse_merge!(as: :user) current_authenticated().present? && \ current_authenticated().class.name.demodulize.underscore == [:as].to_s end |
#store_signed_in_status(client) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/controllers/concerns/nyauth/session_concern.rb', line 56 def store_signed_in_status(client) nyauth_nyan.session.store(client, client.class.name.demodulize.underscore) if Nyauth.configuration. # ex.) cookies.signed[:user_id] .signed[:nyauth_cookie_auth] = "#{client.class.name.demodulize.underscore}:#{client.id}" end end |