[Fix #1285] Add JS to dynamically check the password strength

This commit is contained in:
Mathieu Magnin 2018-09-26 08:54:12 +02:00 committed by gregoirenovel
parent 2507f963b1
commit d1d8d9afe2
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,34 @@
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);
}
}

View file

@ -24,6 +24,10 @@ 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';
@ -33,6 +37,8 @@ const DS = {
togglePrintMenu, togglePrintMenu,
toggleHeaderMenu, toggleHeaderMenu,
scrollMessagerie, scrollMessagerie,
checkPasswordStrength,
displayPasswordStrength,
showMotivation, showMotivation,
motivationCancel, motivationCancel,
toggleChart toggleChart