Module: PublishingPlatform::SSO::ControllerMethods

Included in:
AuthenticationsController
Defined in:
lib/publishing_platform_sso/controller_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/publishing_platform_sso/controller_methods.rb', line 8

def self.included(base)
  base.rescue_from PermissionDeniedError do |e|
    if PublishingPlatform::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 PublishingPlatform::SSO::Config.api_only
    base.helper_method :user_signed_in?
    base.helper_method :current_user
  end
end

Instance Method Details

#authenticate_user!Object



23
24
25
# File 'lib/publishing_platform_sso/controller_methods.rb', line 23

def authenticate_user!
  warden.authenticate!
end

#current_userObject



31
32
33
# File 'lib/publishing_platform_sso/controller_methods.rb', line 31

def current_user
  warden.user if user_signed_in?
end

#logoutObject



35
36
37
# File 'lib/publishing_platform_sso/controller_methods.rb', line 35

def logout
  warden.logout
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/publishing_platform_sso/controller_methods.rb', line 27

def user_signed_in?
  warden && warden.authenticated?
end

#wardenObject



39
40
41
# File 'lib/publishing_platform_sso/controller_methods.rb', line 39

def warden
  request.env["warden"]
end