Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #910 from jloveland/hide-password-validator
Browse files Browse the repository at this point in the history
Hide the password strength progress when the field is empty
  • Loading branch information
ilanbiala committed Oct 17, 2015
2 parents 52f94a2 + 6514044 commit cc486d5
Show file tree
Hide file tree
Showing 11 changed files with 812 additions and 56 deletions.
22 changes: 21 additions & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ module.exports = function (grunt) {
});
});

// Drops the MongoDB database, used in e2e testing
grunt.task.registerTask('dropdb', 'drop the database', function () {
// async mode
var done = this.async();

// Use mongoose configuration
var mongoose = require('./config/lib/mongoose.js');

mongoose.connect(function (db) {
db.connection.db.dropDatabase(function (err) {
if (err) {
console.log(err);
} else {
console.log('Successfully dropped db: ', db.connection.db.databaseName);
}
db.connection.db.close(done);
});
});
});

grunt.task.registerTask('server', 'Starting the server', function () {
// Get the callback
var done = this.async();
Expand All @@ -279,7 +299,7 @@ module.exports = function (grunt) {
grunt.registerTask('test', ['env:test', 'lint', 'mkdir:upload', 'copy:localConfig', 'server', 'mochaTest', 'karma:unit', 'protractor']);
grunt.registerTask('test:server', ['env:test', 'lint', 'server', 'mochaTest']);
grunt.registerTask('test:client', ['env:test', 'lint', 'server', 'karma:unit']);
grunt.registerTask('test:e2e', ['env:test', 'lint', 'server', 'protractor']);
grunt.registerTask('test:e2e', ['env:test', 'lint', 'dropdb', 'server', 'protractor']);

// Run project coverage
grunt.registerTask('coverage', ['env:test', 'lint', 'mocha_istanbul:coverage']);
Expand Down
19 changes: 18 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ gulp.task('karma', function (done) {
}));
});

// Drops the MongoDB database, used in e2e testing
gulp.task('dropdb', function (done) {
// Use mongoose configuration
var mongoose = require('./config/lib/mongoose.js');

mongoose.connect(function (db) {
db.connection.db.dropDatabase(function (err) {
if(err) {
console.log(err);
} else {
console.log('Successfully dropped db: ', db.connection.db.databaseName);
}
db.connection.db.close(done);
});
});
});

// Downloads the selenium webdriver
gulp.task('webdriver_update', webdriver_update);

Expand Down Expand Up @@ -248,7 +265,7 @@ gulp.task('test:client', function (done) {
});

gulp.task('test:e2e', function (done) {
runSequence('env:test', 'lint', 'nodemon', 'protractor', done);
runSequence('env:test', 'lint', 'dropdb', 'nodemon', 'protractor', done);
});

// Run the project in development mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,41 @@ angular.module('users')
.directive('passwordValidator', ['PasswordValidator', function(PasswordValidator) {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.unshift(function (password) {
var result = PasswordValidator.getResult(password);
var strengthIdx = 0;
link: function(scope, element, attrs, ngModel) {
ngModel.$validators.requirements = function (password) {
var status = true;
if (password) {
var result = PasswordValidator.getResult(password);
var requirementsIdx = 0;

// Strength Meter - visual indicator for users
var strengthMeter = [
{ color: 'danger', progress: '20' },
{ color: 'warning', progress: '40' },
{ color: 'info', progress: '60' },
{ color: 'primary', progress: '80' },
{ color: 'success', progress: '100' }
];
var strengthMax = strengthMeter.length;
// Requirements Meter - visual indicator for users
var requirementsMeter = [
{ color: 'danger', progress: '20' },
{ color: 'warning', progress: '40' },
{ color: 'info', progress: '60' },
{ color: 'primary', progress: '80' },
{ color: 'success', progress: '100' }
];

if (result.errors.length < strengthMeter.length) {
strengthIdx = strengthMeter.length - result.errors.length - 1;
}
if (result.errors.length < requirementsMeter.length) {
requirementsIdx = requirementsMeter.length - result.errors.length - 1;
}

scope.strengthColor = strengthMeter[strengthIdx].color;
scope.strengthProgress = strengthMeter[strengthIdx].progress;
scope.requirementsColor = requirementsMeter[requirementsIdx].color;
scope.requirementsProgress = requirementsMeter[requirementsIdx].progress;

if (result.errors.length) {
scope.popoverMsg = PasswordValidator.getPopoverMsg();
scope.passwordErrors = result.errors;
modelCtrl.$setValidity('strength', false);
return undefined;
} else {
scope.popoverMsg = '';
modelCtrl.$setValidity('strength', true);
return password;
if (result.errors.length) {
scope.popoverMsg = PasswordValidator.getPopoverMsg();
scope.passwordErrors = result.errors;
status = false;
} else {
scope.popoverMsg = '';
scope.passwordErrors = [];
status = true;
}
}
});
return status;
};
}
};
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ angular.module('users')
scope: {
passwordVerify: '='
},
link: function(scope, element, attrs, modelCtrl) {
link: function(scope, element, attrs, ngModel) {
var status = true;
scope.$watch(function() {
var combined;
if (scope.passwordVerify || modelCtrl.$viewValue) {
combined = scope.passwordVerify + '_' + modelCtrl.$viewValue;
if (scope.passwordVerify || ngModel) {
combined = scope.passwordVerify + '_' + ngModel;
}
return combined;
}, function(value) {
if (value) {
modelCtrl.$parsers.unshift(function(viewValue) {
ngModel.$validators.passwordVerify = function (password) {
var origin = scope.passwordVerify;
if (origin !== viewValue) {
modelCtrl.$setValidity('passwordVerify', false);
return undefined;
} else {
modelCtrl.$setValidity('passwordVerify', true);
return viewValue;
}
});
return (origin !== password) ? false : true;
};
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ <h3 class="col-md-12 text-center">Or sign up using your email</h3>
<div ng-messages="userForm.password.$error" role="alert">
<p class="help-block error-text" ng-message="required">Password is required.</p>
<div ng-repeat="passwordError in passwordErrors">
<p class="help-block error-text" ng-show="userForm.password.$error.strength">{{passwordError}}</p>
<p class="help-block error-text" ng-show="userForm.password.$error.requirements">{{passwordError}}</p>
</div>
</div>
</div>
<div class="form-group" ng-show="!userForm.password.$pristine">
<label>Password Strength</label>
<progressbar value="strengthProgress" type="{{strengthColor}}"><span style="color:white; white-space:nowrap;">{{strengthProgress}}%</span></progressbar>
<div class="form-group" ng-show="!userForm.password.$error.required">
<label>Password Requirements</label>
<progressbar value="requirementsProgress" type="{{requirementsColor}}"><span style="color:white; white-space:nowrap;">{{requirementsProgress}}%</span></progressbar>
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-primary">Sign up</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3 class="col-md-12 text-center">Reset your password</h3>
<div ng-messages="resetPasswordForm.newPassword.$error" role="alert">
<p class="help-block error-text" ng-message="required">Enter a new password.</p>
<div ng-repeat="passwordError in passwordErrors">
<p class="help-block error-text" ng-show="resetPasswordForm.newPassword.$error.strength">{{passwordError}}</p>
<p class="help-block error-text" ng-show="resetPasswordForm.newPassword.$error.requirements">{{passwordError}}</p>
</div>
</div>
</div>
Expand All @@ -21,9 +21,9 @@ <h3 class="col-md-12 text-center">Reset your password</h3>
<p class="help-block error-text" ng-show=resetPasswordForm.verifyPassword.$error.passwordVerify>Passwords do not match.</p>
</div>
</div>
<div class="form-group" ng-show="!resetPasswordForm.newPassword.$pristine">
<label>Password Strength</label>
<progressbar value="strengthProgress" type="{{strengthColor}}"><span style="color:white; white-space:nowrap;">{{strengthProgress}}%</span></progressbar>
<div class="form-group" ng-show="!resetPasswordForm.newPassword.$error.required">
<label>Password Requirements</label>
<progressbar value="requirementsProgress" type="{{requirementsColor}}"><span style="color:white; white-space:nowrap;">{{requirementsProgress}}%</span></progressbar>
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-primary">Update Password</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div ng-messages="passwordForm.newPassword.$error" role="alert">
<p class="help-block error-text" ng-message="required">Enter a new password.</p>
<div ng-repeat="passwordError in passwordErrors">
<p class="help-block error-text" ng-show="passwordForm.newPassword.$error.strength">{{passwordError}}</p>
<p class="help-block error-text" ng-show="passwordForm.newPassword.$error.requirements">{{passwordError}}</p>
</div>
</div>
</div>
Expand All @@ -27,9 +27,9 @@
<p class="help-block error-text" ng-show=passwordForm.verifyPassword.$error.passwordVerify>Passwords do not match.</p>
</div>
</div>
<div class="form-group" ng-show="!passwordForm.newPassword.$pristine">
<label>Password Strength</label>
<progressbar value="strengthProgress" type="{{strengthColor}}"><span style="color:white; white-space:nowrap;">{{strengthProgress}}%</span></progressbar>
<div class="form-group" ng-show="!passwordForm.newPassword.$error.required">
<label>Password Requirements</label>
<progressbar value="requirementsProgress" type="{{requirementsColor}}"><span style="color:white; white-space:nowrap;">{{requirementsProgress}}%</span></progressbar>
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-primary">Save Password</button>
Expand Down
Loading

0 comments on commit cc486d5

Please sign in to comment.