[Fix #1285] Add JS to dynamically check the password strength
This commit is contained in:
parent
2507f963b1
commit
d1d8d9afe2
2 changed files with 40 additions and 0 deletions
34
app/javascript/new_design/password-strength.js
Normal file
34
app/javascript/new_design/password-strength.js
Normal 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);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,10 @@ import { toggleCondidentielExplanation } from '../new_design/avis';
|
|||
import { togglePrintMenu } from '../new_design/dossier';
|
||||
import { toggleHeaderMenu } from '../new_design/header';
|
||||
import { scrollMessagerie } from '../new_design/messagerie';
|
||||
import {
|
||||
checkPasswordStrength,
|
||||
displayPasswordStrength
|
||||
} from '../new_design/password-strength';
|
||||
import { showMotivation, motivationCancel } from '../new_design/state-button';
|
||||
import { toggleChart } from '../new_design/toggle-chart';
|
||||
|
||||
|
@ -33,6 +37,8 @@ const DS = {
|
|||
togglePrintMenu,
|
||||
toggleHeaderMenu,
|
||||
scrollMessagerie,
|
||||
checkPasswordStrength,
|
||||
displayPasswordStrength,
|
||||
showMotivation,
|
||||
motivationCancel,
|
||||
toggleChart
|
||||
|
|
Loading…
Reference in a new issue