Synchronised password when user or gestionnaire change this

This commit is contained in:
Xavier J 2016-12-07 17:35:45 +01:00
parent 7cb2e80a3d
commit 1c2b2010d1
4 changed files with 40 additions and 0 deletions

View file

@ -1,5 +1,6 @@
class Gestionnaires::PasswordsController < Devise::PasswordsController
after_action :try_to_authenticate_user, only: %i(update)
after_action :try_to_authenticate_administrateur, only: %i(update)
# GET /resource/password/new
# def new
@ -38,4 +39,11 @@ class Gestionnaires::PasswordsController < Devise::PasswordsController
sign_in user if user
end
end
def try_to_authenticate_administrateur
if gestionnaire_signed_in?
administrateur = Administrateur.find_by(email: current_gestionnaire.email)
sign_in administrateur if administrateur
end
end
end

View file

@ -1,5 +1,6 @@
class Users::PasswordsController < Devise::PasswordsController
after_action :try_to_authenticate_gestionnaire, only: %i(update)
after_action :try_to_authenticate_administrateur, only: %i(update)
# GET /resource/password/new
# def new
@ -38,4 +39,11 @@ class Users::PasswordsController < Devise::PasswordsController
sign_in gestionnaire if gestionnaire
end
end
def try_to_authenticate_administrateur
if user_signed_in?
administrateur = Administrateur.find_by(email: current_user.email)
sign_in administrateur if administrateur
end
end
end

View file

@ -9,11 +9,13 @@ describe Gestionnaires::PasswordsController, type: :controller do
context "unified login" do
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'password') }
before do
allow(Features).to receive(:unified_login).and_return(true)
@token = gestionnaire.send(:set_reset_password_token)
user # make sure it's created
administrateur # make sure it's created
end
it "also signs user in" do
@ -25,6 +27,16 @@ describe Gestionnaires::PasswordsController, type: :controller do
expect(subject.current_gestionnaire).to eq(gestionnaire)
expect(subject.current_user).to eq(user)
end
it "also signs administrateur in" do
put :update, params: {gestionnaire: {
reset_password_token: @token,
password: "supersecret",
password_confirmation: "supersecret",
}}
expect(subject.current_administrateur).to eq(administrateur)
expect(subject.current_user).to eq(user)
end
end
end
end

View file

@ -9,11 +9,13 @@ describe Users::PasswordsController, type: :controller do
context "unified login" do
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'password') }
before do
allow(Features).to receive(:unified_login).and_return(true)
@token = user.send(:set_reset_password_token)
gestionnaire # make sure it's created
administrateur # make sure it's created
end
it "also signs gestionnaire in" do
@ -25,6 +27,16 @@ describe Users::PasswordsController, type: :controller do
expect(subject.current_user).to eq(user)
expect(subject.current_gestionnaire).to eq(gestionnaire)
end
it "also signs administrateur in" do
put :update, params: {user: {
reset_password_token: @token,
password: "supersecret",
password_confirmation: "supersecret",
}}
expect(subject.current_user).to eq(user)
expect(subject.current_administrateur).to eq(administrateur)
end
end
end
end