Class: Authem::Support
- Inherits:
-
Object
- Object
- Authem::Support
- Defined in:
- lib/authem/support.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
- #clear_for(record) ⇒ Object
- #current ⇒ Object
- #deny_access ⇒ Object
-
#initialize(role, controller) ⇒ Support
constructor
A new instance of Support.
- #require_role ⇒ Object
- #sign_in(record, options = {}) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
Constructor Details
#initialize(role, controller) ⇒ Support
Returns a new instance of Support.
5 6 7 |
# File 'lib/authem/support.rb', line 5 def initialize(role, controller) @role, @controller = role, controller end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/authem/support.rb', line 3 def controller @controller end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
3 4 5 |
# File 'lib/authem/support.rb', line 3 def role @role end |
Instance Method Details
#clear_for(record) ⇒ Object
37 38 39 40 41 |
# File 'lib/authem/support.rb', line 37 def clear_for(record) check_record! record sign_out Authem::Session.by_subject(record).where(role: role_name).delete_all end |
#current ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/authem/support.rb', line 9 def current if ivar_defined? ivar_get else ivar_set(fetch_subject_by_token) end end |
#deny_access ⇒ Object
50 51 52 53 |
# File 'lib/authem/support.rb', line 50 def deny_access # default landing point for deny_#{role_name}_access fail NotImplementedError, "No strategy for require_#{role_name} defined. Please define `deny_#{role_name}_access` method in your controller" end |
#require_role ⇒ Object
43 44 45 46 47 48 |
# File 'lib/authem/support.rb', line 43 def require_role unless signed_in? session[:return_to_url] = request.url unless request.xhr? controller.send "deny_#{role_name}_access" end end |
#sign_in(record, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/authem/support.rb', line 17 def sign_in(record, ={}) check_record! record ivar_set record auth_session = create_auth_session(record, ) save_session auth_session auth_session if [:remember] auth_session end |
#sign_out ⇒ Object
30 31 32 33 34 35 |
# File 'lib/authem/support.rb', line 30 def sign_out ivar_set nil Authem::Session.where(role: role_name, token: current_auth_token).delete_all .delete key, domain: :all session.delete key end |
#signed_in? ⇒ Boolean
26 27 28 |
# File 'lib/authem/support.rb', line 26 def signed_in? current.present? end |