Module: GDS::SSO::ControllerMethods
Defined Under Namespace
Classes: PermissionDeniedException
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/gds-sso/controller_methods.rb', line 15
def self.included(base)
base.rescue_from PermissionDeniedError do |e|
if GDS::SSO::Config.api_only
render json: { message: e.message }, status: :forbidden
else
render "authorisations/unauthorised", layout: "unauthorised", status: :forbidden, locals: { message: e.message }
end
end
unless GDS::SSO::Config.api_only
base.helper_method :user_signed_in?
base.helper_method :current_user
end
end
|
Instance Method Details
#authenticate_user! ⇒ Object
38
39
40
|
# File 'lib/gds-sso/controller_methods.rb', line 38
def authenticate_user!
warden.authenticate!
end
|
#authorise_user!(permissions) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/gds-sso/controller_methods.rb', line 30
def authorise_user!(permissions)
authenticate_user!
GDS::SSO::AuthoriseUser.call(current_user, permissions)
end
|
#current_user ⇒ Object
50
51
52
|
# File 'lib/gds-sso/controller_methods.rb', line 50
def current_user
warden.user if user_signed_in?
end
|
#logout ⇒ Object
54
55
56
|
# File 'lib/gds-sso/controller_methods.rb', line 54
def logout
warden.logout
end
|
#user_remotely_signed_out? ⇒ Boolean
42
43
44
|
# File 'lib/gds-sso/controller_methods.rb', line 42
def user_remotely_signed_out?
warden && warden.authenticated? && warden.user.remotely_signed_out?
end
|
#user_signed_in? ⇒ Boolean
46
47
48
|
# File 'lib/gds-sso/controller_methods.rb', line 46
def user_signed_in?
warden && warden.authenticated? && !warden.user.remotely_signed_out?
end
|
#warden ⇒ Object
58
59
60
|
# File 'lib/gds-sso/controller_methods.rb', line 58
def warden
request.env["warden"]
end
|