Module: YiffSpace::Auth::Helper
- Extended by:
- ActiveSupport::Concern
- Included in:
- Scoped
- Defined in:
- lib/yiffspace/auth/helper.rb
Defined Under Namespace
Modules: ClassMethods, Scoped
Instance Method Summary
collapse
Instance Method Details
#auth=(value) ⇒ Object
43
44
45
46
|
# File 'lib/yiffspace/auth/helper.rb', line 43
def auth=(value)
value = nil if value.is_a?(AuthInfo::Anonymous)
session[auth_client_config.auth_session_key] = value&.to_session
end
|
#auth? ⇒ Boolean
39
40
41
|
# File 'lib/yiffspace/auth/helper.rb', line 39
def auth?
auth_raw.present? && !auth.anonymous?
end
|
#auth_client_config ⇒ Object
Returns the Auth::Client for the current request. In auth engine controllers this is resolved from the routing default set by Engine.for; in host app controllers it falls back to the default registered client. Override in your controller to choose a specific client when multiple are registered.
102
103
104
105
|
# File 'lib/yiffspace/auth/helper.rb', line 102
def auth_client_config
client_name = self.client_name
client_name.present? ? YiffSpace::Auth[client_name.to_sym] : YiffSpace::Auth.default
end
|
#auth_raw ⇒ Object
29
30
31
|
# File 'lib/yiffspace/auth/helper.rb', line 29
def auth_raw
session[auth_client_config.auth_session_key]
end
|
#client_name ⇒ Object
107
108
109
|
# File 'lib/yiffspace/auth/helper.rb', line 107
def client_name
respond_to?(:request, true) && request.env[CLIENT_NAME_ENV]
end
|
#client_name=(value) ⇒ Object
111
112
113
|
# File 'lib/yiffspace/auth/helper.rb', line 111
def client_name=(value)
request.env[CLIENT_NAME_ENV] = value.to_sym
end
|
#full_reset! ⇒ Object
75
76
77
78
|
# File 'lib/yiffspace/auth/helper.rb', line 75
def full_reset!
reset_auth!
reset_user!
end
|
#has_permission?(name) ⇒ Boolean
88
89
90
91
92
|
# File 'lib/yiffspace/auth/helper.rb', line 88
def has_permission?(name)
return false unless user?
auth.permissions.has?(name)
end
|
#logged_in? ⇒ Boolean
84
85
86
|
# File 'lib/yiffspace/auth/helper.rb', line 84
def logged_in?
user?
end
|
#require_auth(path) ⇒ Object
80
81
82
|
# File 'lib/yiffspace/auth/helper.rb', line 80
def require_auth(path)
redirect_to(path) unless user?
end
|
#reset_auth! ⇒ Object
48
49
50
|
# File 'lib/yiffspace/auth/helper.rb', line 48
def reset_auth!
session.delete(auth_client_config.auth_session_key)
end
|
#reset_user! ⇒ Object
71
72
73
|
# File 'lib/yiffspace/auth/helper.rb', line 71
def reset_user!
session.delete(auth_client_config.user_session_key)
end
|
#url_helpers ⇒ Object
94
95
96
|
# File 'lib/yiffspace/auth/helper.rb', line 94
def url_helpers
YiffSpace::Auth::Engine.for(client_name).routes.url_helpers
end
|
#user=(value) ⇒ Object
66
67
68
69
|
# File 'lib/yiffspace/auth/helper.rb', line 66
def user=(value)
value = nil if value.is_a?(UserInfo::Anonymous)
session[auth_client_config.user_session_key] = value&.to_session
end
|
#user? ⇒ Boolean
62
63
64
|
# File 'lib/yiffspace/auth/helper.rb', line 62
def user?
user_raw.present? && !user.anonymous?
end
|
#user_raw ⇒ Object
52
53
54
|
# File 'lib/yiffspace/auth/helper.rb', line 52
def user_raw
session[auth_client_config.user_session_key]
end
|