generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if user is authenticated before visiting the home page
Co-authored-by: Cait <[email protected]> Co-authored-by: Efua Akumanyi <[email protected]>
- Loading branch information
1 parent
8e73f2a
commit 9983bf7
Showing
8 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class ApplicationController < ActionController::Base | ||
def new_session_path(scope) | ||
new_user_session_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class HomeController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show | ||
render body: "Hello from Staff Device" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
def cognito_idp | ||
@user = User.from_omniauth(request.env["omniauth.auth"]) | ||
|
||
if @user.persisted? | ||
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated | ||
set_flash_message(:notice, :success, kind: "Cognito IDP") if is_navigational_format? | ||
end | ||
end | ||
|
||
def failure | ||
redirect_to root_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>Log in</h2> | ||
|
||
<%= link_to "Sign in with Cognito", user_cognito_idp_omniauth_authorize_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p>Hello from Staff Device</p> | ||
|
||
<%= link_to "Logout", destroy_user_session_path, method: :delete %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
Rails.application.routes.draw do | ||
devise_for :users | ||
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } | ||
devise_scope :user do | ||
get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session | ||
delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session | ||
end | ||
|
||
get "/healthcheck", to: "monitoring#healthcheck" | ||
root "home#show" | ||
end |