Replace password strength js with ujs
This commit is contained in:
parent
f0aa78c8a8
commit
3c66fceba5
7 changed files with 9 additions and 44 deletions
|
@ -32,8 +32,7 @@ class Administrateurs::ActivateController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_password_strength
|
def test_password_strength
|
||||||
score = Zxcvbn.test(params[:password], [], ZXCVBN_DICTIONNARIES).score
|
@score = Zxcvbn.test(params[:administrateur][:password], [], ZXCVBN_DICTIONNARIES).score
|
||||||
render json: { score: score }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
import $ from 'jquery';
|
|
||||||
|
|
||||||
export function displayPasswordStrength(strengthBarId, score) {
|
|
||||||
var $bar = $('#' + strengthBarId),
|
|
||||||
passwordMessage;
|
|
||||||
|
|
||||||
$bar.removeClass('strength-1 strength-2 strength-3 strength-4');
|
|
||||||
|
|
||||||
if (score < 4) {
|
|
||||||
passwordMessage = 'Mot de passe pas assez complexe';
|
|
||||||
} else {
|
|
||||||
passwordMessage = 'Mot de passe suffisamment complexe';
|
|
||||||
}
|
|
||||||
|
|
||||||
$bar.text(passwordMessage);
|
|
||||||
$bar.addClass('strength-' + score);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkPasswordStrength(event, strengthBarId) {
|
|
||||||
var $target = $(event.target),
|
|
||||||
password = $target.val();
|
|
||||||
|
|
||||||
if (password.length > 2) {
|
|
||||||
$.post(
|
|
||||||
'/admin/activate/test_password_strength',
|
|
||||||
{ password: password },
|
|
||||||
function(data) {
|
|
||||||
displayPasswordStrength(strengthBarId, data.score);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
displayPasswordStrength(strengthBarId, 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,10 +24,6 @@ import { toggleCondidentielExplanation } from '../new_design/avis';
|
||||||
import { togglePrintMenu } from '../new_design/dossier';
|
import { togglePrintMenu } from '../new_design/dossier';
|
||||||
import { toggleHeaderMenu } from '../new_design/header';
|
import { toggleHeaderMenu } from '../new_design/header';
|
||||||
import { scrollMessagerie } from '../new_design/messagerie';
|
import { scrollMessagerie } from '../new_design/messagerie';
|
||||||
import {
|
|
||||||
checkPasswordStrength,
|
|
||||||
displayPasswordStrength
|
|
||||||
} from '../new_design/password-strength';
|
|
||||||
import { showMotivation, motivationCancel } from '../new_design/state-button';
|
import { showMotivation, motivationCancel } from '../new_design/state-button';
|
||||||
import { toggleChart } from '../new_design/toggle-chart';
|
import { toggleChart } from '../new_design/toggle-chart';
|
||||||
|
|
||||||
|
@ -37,8 +33,6 @@ const DS = {
|
||||||
togglePrintMenu,
|
togglePrintMenu,
|
||||||
toggleHeaderMenu,
|
toggleHeaderMenu,
|
||||||
scrollMessagerie,
|
scrollMessagerie,
|
||||||
checkPasswordStrength,
|
|
||||||
displayPasswordStrength,
|
|
||||||
showMotivation,
|
showMotivation,
|
||||||
motivationCancel,
|
motivationCancel,
|
||||||
toggleChart
|
toggleChart
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#strength-bar.password-strength{ class: "strength-#{score}" }
|
||||||
|
- if score < 4
|
||||||
|
Mot de passe pas assez complexe
|
||||||
|
- else
|
||||||
|
Mot de passe suffisamment complexe
|
|
@ -16,7 +16,7 @@
|
||||||
= f.label :password do
|
= f.label :password do
|
||||||
Mot de passe
|
Mot de passe
|
||||||
|
|
||||||
= f.password_field :password, placeholder: 'Mot de passe', onKeyUp: "javascript:DS.checkPasswordStrength(event, 'strength-bar', 'submit-password');"
|
= f.password_field :password, placeholder: 'Mot de passe', data: { remote: true, url: admin_activate_test_password_strength_path }
|
||||||
|
|
||||||
#strength-bar.password-strength
|
#strength-bar.password-strength
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<%= render_to_element('#strength-bar', partial: 'password_strength', outer: true, locals: { score: @score }) %>
|
|
@ -175,7 +175,7 @@ Rails.application.routes.draw do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get 'activate' => '/administrateurs/activate#new'
|
get 'activate' => '/administrateurs/activate#new'
|
||||||
patch 'activate' => '/administrateurs/activate#create'
|
patch 'activate' => '/administrateurs/activate#create'
|
||||||
post 'activate/test_password_strength' => '/administrateurs/activate#test_password_strength'
|
get 'activate/test_password_strength' => '/administrateurs/activate#test_password_strength'
|
||||||
get 'sign_in' => '/administrateurs/sessions#new'
|
get 'sign_in' => '/administrateurs/sessions#new'
|
||||||
get 'procedures/archived' => 'procedures#archived'
|
get 'procedures/archived' => 'procedures#archived'
|
||||||
get 'procedures/draft' => 'procedures#draft'
|
get 'procedures/draft' => 'procedures#draft'
|
||||||
|
|
Loading…
Reference in a new issue