Remove all devise route and controller for instructeur and administrateur

This commit is contained in:
simon lehericey 2019-08-08 11:06:28 +02:00 committed by Pierre de La Morinerie
parent 1fb26451d3
commit 5bda753735
4 changed files with 4 additions and 168 deletions

View file

@ -1,59 +1,4 @@
class Administrateurs::PasswordsController < Devise::PasswordsController
after_action :try_to_authenticate_user, only: [:update]
after_action :try_to_authenticate_instructeur, only: [:update]
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# # params[:user][:password_confirmation] = params[:user][:password]
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
def try_to_authenticate_user
if administrateur_signed_in?
user = User.find_by(email: current_administrateur.email)
if user
sign_in user
end
end
end
def try_to_authenticate_instructeur
if administrateur_signed_in?
instructeur = Instructeur.find_by(email: current_administrateur.email)
if instructeur
sign_in instructeur
end
end
end
class Administrateurs::PasswordsController < ApplicationController
def test_strength
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
@min_length = PASSWORD_MIN_LENGTH
@ -64,6 +9,6 @@ class Administrateurs::PasswordsController < Devise::PasswordsController
private
def password_params
params.require(:administrateur).permit(:reset_password_token, :password)
params.require(:administrateur).permit(:password)
end
end

View file

@ -1,55 +0,0 @@
class Instructeurs::PasswordsController < Devise::PasswordsController
after_action :try_to_authenticate_user, only: [:update]
after_action :try_to_authenticate_administrateur, only: [:update]
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
def try_to_authenticate_user
if instructeur_signed_in?
user = User.find_by(email: current_instructeur.email)
if user
sign_in user
end
end
end
def try_to_authenticate_administrateur
if instructeur_signed_in?
administrateur = Administrateur.find_by(email: current_instructeur.email)
if administrateur
sign_in administrateur
end
end
end
end

View file

@ -77,13 +77,9 @@ Rails.application.routes.draw do
omniauth_callbacks: 'administrations/omniauth_callbacks'
}
devise_for :administrateurs, controllers: {
passwords: 'administrateurs/passwords'
}, skip: [:registrations]
devise_for :administrateurs, skip: :all
devise_for :instructeurs, controllers: {
passwords: 'instructeurs/passwords'
}, skip: [:registrations]
devise_for :instructeurs, skip: :all
devise_for :users, controllers: {
sessions: 'users/sessions',
@ -98,11 +94,6 @@ Rails.application.routes.draw do
get 'lien-envoye/:email' => 'users/sessions#link_sent', constraints: { email: /.*/ }, as: 'link_sent'
end
devise_scope :instructeur do
get '/instructeurs/edit' => 'instructeurs/registrations#edit', :as => 'edit_instructeurs_registration'
put '/instructeurs' => 'instructeurs/registrations#update', :as => 'instructeurs_registration'
end
devise_scope :administrateur do
get '/administrateurs/password/test_strength' => 'administrateurs/passwords#test_strength'
end

View file

@ -1,45 +0,0 @@
require "spec_helper"
describe Instructeurs::PasswordsController, type: :controller do
before do
@request.env["devise.mapping"] = Devise.mappings[:instructeur]
end
describe "update" do
context "unified login" do
let(:user) { create(:user, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') }
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') }
let(:instructeur) { administrateur.instructeur }
before do
@token = instructeur.send(:set_reset_password_token)
user # make sure it's created
administrateur # make sure it's created
end
it "also signs user in" do
put :update, params: {
instructeur: {
reset_password_token: @token,
password: "démarches-simplifiées-pwd",
password_confirmation: "démarches-simplifiées-pwd"
}
}
expect(subject.current_instructeur).to eq(instructeur)
expect(subject.current_user).to eq(user)
end
it "also signs administrateur in" do
put :update, params: {
instructeur: {
reset_password_token: @token,
password: "démarches-simplifiées-pwd",
password_confirmation: "démarches-simplifiées-pwd"
}
}
expect(subject.current_administrateur).to eq(administrateur)
expect(subject.current_user).to eq(user)
end
end
end
end