super_admin: check password complexity client side
This commit is contained in:
parent
90d7ee872e
commit
94b3ec942b
4 changed files with 32 additions and 4 deletions
|
@ -3,4 +3,17 @@ class SuperAdmins::PasswordsController < Devise::PasswordsController
|
|||
super
|
||||
self.resource.disable_otp!
|
||||
end
|
||||
|
||||
def test_strength
|
||||
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
|
||||
@min_length = PASSWORD_MIN_LENGTH
|
||||
@min_complexity = PASSWORD_COMPLEXITY_FOR_ADMIN
|
||||
render 'shared/password/test_strength'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def password_params
|
||||
params.require(:super_admin).permit(:password)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
= f.hidden_field :reset_password_token
|
||||
|
||||
= f.label 'Nouveau mot de passe'
|
||||
= f.password_field :password, autofocus: true, autocomplete: 'off'
|
||||
|
||||
= f.label 'Confirmez le nouveau mot de passe'
|
||||
= f.password_field :password_confirmation, autocomplete: 'off'
|
||||
= render partial: 'shared/password/edit_password', locals: { form: f, controller: 'super_admins/passwords' }
|
||||
|
||||
= f.submit 'Changer le mot de passe', class: 'button primary'
|
||||
|
||||
= f.submit 'Changer le mot de passe', class: 'button large primary expand', id: "submit-password", data: { disable_with: "Envoi..." }
|
||||
|
|
|
@ -84,6 +84,10 @@ Rails.application.routes.draw do
|
|||
passwords: 'super_admins/passwords'
|
||||
}
|
||||
|
||||
devise_scope :super_admin do
|
||||
get '/super_admins/password/test_strength' => 'super_admins/passwords#test_strength'
|
||||
end
|
||||
|
||||
get 'super_admins/edit_otp', to: 'super_admins#edit_otp', as: 'edit_super_admin_otp'
|
||||
put 'super_admins/enable_otp', to: 'super_admins#enable_otp', as: 'enable_super_admin_otp'
|
||||
|
||||
|
|
12
spec/controllers/super_admins/passwords_controller_spec.rb
Normal file
12
spec/controllers/super_admins/passwords_controller_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
describe SuperAdmins::PasswordsController, type: :controller do
|
||||
describe '#test_strength' do
|
||||
it 'calculate score' do
|
||||
password = "bonjour"
|
||||
@request.env["devise.mapping"] = Devise.mappings[:super_admin]
|
||||
|
||||
get 'test_strength', xhr: true, params: { super_admin: { password: password } }
|
||||
|
||||
expect(assigns(:score)).to be_present
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue