Profil: display token only once
This commit is contained in:
parent
bd04972f65
commit
17285b0368
6 changed files with 54 additions and 37 deletions
15
app/assets/stylesheets/new_design/profil.scss
Normal file
15
app/assets/stylesheets/new_design/profil.scss
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
@import "constants";
|
||||||
|
|
||||||
|
#profil-page {
|
||||||
|
b {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
margin: 3 * $default-spacer 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 16px auto;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
module NewAdministrateur
|
module NewAdministrateur
|
||||||
class ProfilController < AdministrateurController
|
class ProfilController < AdministrateurController
|
||||||
def show
|
def show
|
||||||
@administrateur = current_administrateur
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def renew_api_token
|
def renew_api_token
|
||||||
flash[:notice] = "Votre token d'API a été regénéré."
|
|
||||||
current_administrateur.renew_api_token
|
current_administrateur.renew_api_token
|
||||||
redirect_to profil_path
|
@token = current_administrateur.api_token
|
||||||
|
flash.now.notice = 'Votre jeton a été regénéré.'
|
||||||
|
render :show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
#profil-page.container
|
#profil-page.container
|
||||||
%h1 Profil
|
%h1 Profil
|
||||||
|
|
||||||
%p API TOKEN : #{@administrateur.api_token}
|
.card
|
||||||
|
.card-title Jeton d'identification de l'API (token)
|
||||||
|
%p Ce jeton est nécessaire pour effectuer des appels vers l'API de demarches-simplifiees.fr.
|
||||||
|
|
||||||
= link_to "Regénérer mon token",
|
- if defined?(@token)
|
||||||
renew_api_token_path,
|
%p Jeton : <b>#{@token}</b>
|
||||||
method: :post,
|
%p Pour des raisons de sécurité, ce jeton ne sera plus ré-affiché, notez-le bien.
|
||||||
class: "button primary",
|
|
||||||
data: { confirm: "Confirmez-vous la regénération de votre token ? Les applications qui l'utilisent actuellement seront bloquées.",
|
- else
|
||||||
disable: true }
|
%p Pour des raisons de sécurité, nous ne pouvons vous l'afficher que lors de sa génération.
|
||||||
|
%p Attention, si vous avez déjà des applications qui utilisent votre jeton, le regénérer bloquera leurs accès à l'API.
|
||||||
|
|
||||||
|
= link_to "Regénérer et afficher mon jeton",
|
||||||
|
renew_api_token_path,
|
||||||
|
method: :post,
|
||||||
|
class: "button primary",
|
||||||
|
data: { confirm: "Confirmez-vous la regénération de votre jeton ? Les applications qui l'utilisent actuellement seront bloquées.",
|
||||||
|
disable: true }
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Admin::ProfileController, type: :controller do
|
|
||||||
it { expect(described_class).to be < AdminController }
|
|
||||||
let(:administrateur) { create(:administrateur) }
|
|
||||||
|
|
||||||
before { sign_in(administrateur) }
|
|
||||||
|
|
||||||
describe 'POST #renew_api_token' do
|
|
||||||
subject { post :renew_api_token }
|
|
||||||
|
|
||||||
it { expect{ subject }.to change { administrateur.reload.api_token } }
|
|
||||||
|
|
||||||
it { subject; expect(response.status).to redirect_to(profil_path) }
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe NewAdministrateur::ProfilController, type: :controller do
|
||||||
|
let(:administrateur) { create(:administrateur) }
|
||||||
|
|
||||||
|
before { sign_in(administrateur) }
|
||||||
|
|
||||||
|
describe 'POST #renew_api_token' do
|
||||||
|
before do
|
||||||
|
allow(administrateur).to receive(:renew_api_token)
|
||||||
|
allow(controller).to receive(:current_administrateur) { administrateur }
|
||||||
|
post :renew_api_token
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(administrateur).to have_received(:renew_api_token) }
|
||||||
|
it { expect(response.status).to render_template(:show) }
|
||||||
|
it { expect(flash.notice).to eq('Votre jeton a été regénéré.') }
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,11 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe 'admin/profile/show.html.haml', type: :view do
|
|
||||||
let(:token) { 'super_token' }
|
|
||||||
let(:admin) { create(:administrateur, api_token: token) }
|
|
||||||
before do
|
|
||||||
assign(:administrateur, admin)
|
|
||||||
render
|
|
||||||
end
|
|
||||||
it { expect(rendered).to have_content(token) }
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue