Fix #1131 Add password strength validation

This commit is contained in:
Nicolas Le Goff
2013-06-14 16:55:29 +02:00
parent 6dafcaf775
commit fc5fea2c2f
13 changed files with 158 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ require([
"jquery",
"i18n",
"apps/login/home/common",
"apps/login/home/views/form"
"apps/login/home/views/forms/passwordSetter"
], function($, i18n, Common, RenewPassword) {
i18n.init({
resGetPath: Common.languagePath,

View File

@@ -12,7 +12,7 @@ require([
"jquery",
"i18n",
"apps/login/home/common",
"apps/login/home/views/form"
"apps/login/home/views/forms/passwordSetter"
], function($, i18n, Common, RegisterForm) {
var fieldsConfiguration = [];

View File

@@ -11,7 +11,7 @@ require([
"jquery",
"i18n",
"apps/login/home/common",
"apps/login/home/views/form"
"apps/login/home/views/forms/passwordSetter"
], function($, i18n, Common, RenewPassword) {
i18n.init({
resGetPath: Common.languagePath,

View File

@@ -15,7 +15,7 @@ define([
"common/validator",
"apps/login/home/views/input"
], function($, _, Backbone, bootstrap, Validator, InputView) {
var RegisterForm = Backbone.View.extend({
var Form = Backbone.View.extend({
events: {
"submit": "_onSubmit"
},
@@ -82,5 +82,5 @@ define([
}
});
return RegisterForm;
return Form;
});

View File

@@ -0,0 +1,80 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"i18n",
"backbone",
"bootstrap",
"apps/login/home/views/form"
], function($, _, i18n, Backbone, bootstrap, FormView) {
var PasswordSetterForm = FormView.extend({
events: function(){
return _.extend({},FormView.prototype.events,{
'keyup input[type=password]' : 'onPasswordKeyup'
});
},
onPasswordKeyup : function(event) {
var input = $(event.target);
var password = input.val();
var inputView = this.inputViews[input.attr("name")];
var bg = $(".password_strength_bg", inputView.$el);
var label = $(".password_strength_label", inputView.$el);
var desc = $(".password_strength_desc", inputView.$el);
var css = {
"width": "0%",
"background-color": "rgb(39, 39, 30)"
};
var result = "";
if (password.length > 0 ) {
var passMeter = zxcvbn(input.val());
switch (passMeter.score) {
case 0:
case 1:
css = {
"width": "25%",
"background-color": "rgb(200, 24, 24)"
};
result = i18n.t("weak");
break;
case 2:
css = {
"width": "50%",
"background-color": "rgb(255, 172, 29)"
};
result = i18n.t("ordinary");
break;
case 3:
css = {
"width": "75%",
"background-color": "rgb(166, 192, 96)"
};
result = i18n.t("good");
break;
case 4:
css = {
"width": "100%",
"background-color": "rgb(39, 179, 15)"
};
result = i18n.t("great");
break;
}
}
bg.css(css);
label.css({"color": css["background-color"]});
desc.css({"color": css["background-color"]}).html(result);
}
});
return PasswordSetterForm;
});