generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Création des pages d'authentification pour les utilisateurs 'insiders'
- Loading branch information
Showing
11 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Insider | ||
class ApplicationController < ActionController::Base | ||
include UserLogger | ||
include PageTitle | ||
|
||
layout "application" | ||
|
||
before_action :authenticate_insider_user!, except: :login | ||
before_action :log_user, | ||
:set_overrides, | ||
:infer_page_title | ||
|
||
helper_method :current_user, :current_establishment | ||
|
||
def login; end | ||
|
||
def logout | ||
sign_out(current_insider_user) | ||
|
||
redirect_to after_sign_out_path_for(:insider_user) | ||
end | ||
|
||
protected | ||
|
||
def after_sign_out_path_for(_resource) | ||
new_insider_user_session_path | ||
end | ||
|
||
def current_user | ||
current_insider_user | ||
end | ||
|
||
def current_establishment | ||
nil | ||
end | ||
|
||
def set_overrides | ||
@inhibit_nav = true | ||
@logout_path = :destroy_insider_user_session | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Insider | ||
class User < ApplicationRecord | ||
devise :authenticatable | ||
|
||
validates :uid, :provider, :name, :email, presence: true | ||
|
||
OMNIAUTH_PROVIDERS = if Rails.env.production? | ||
:fim | ||
else | ||
%i[fim developer] | ||
end | ||
|
||
class << self | ||
# ideally all these methods would live in some OIDC-factory but I | ||
# can't figure out a pattern I like quite yet | ||
def from_oidc(attrs) | ||
# we can't use find_or_create because a bunch of fields are mandatory | ||
User.find_or_initialize_by(uid: attrs["uid"], provider: attrs["provider"]).tap do |user| | ||
user.token = attrs["credentials"]["token"] | ||
user.secret = "nope" | ||
user.name = attrs["info"]["name"] | ||
user.email = attrs["info"]["email"] | ||
user.oidc_attributes = attrs | ||
end | ||
end | ||
end | ||
|
||
def to_s | ||
name | ||
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
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,8 @@ | ||
.fr-grid-row.fr-grid-row--gutters#login-page | ||
- User::OMNIAUTH_PROVIDERS.each do |provider| | ||
.fr-col-md-6.fr-col-12 | ||
= render 'shared/connection_panel', | ||
name: t("omniauth.#{provider}.title"), | ||
description: t("omniauth.#{provider}.description"), | ||
button: t("omniauth.#{provider}.button"), | ||
path: "/users/auth/#{provider}" |
File renamed without changes.
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