Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #125 from AppliedIS/password-validation
Browse files Browse the repository at this point in the history
Password complexity validation
  • Loading branch information
jefferey committed Nov 10, 2016
2 parents 2fed107 + d79462a commit 72f1727
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = function(ngModule) {
vm.emailVerificationError = true;
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));
});
}
}

$scope.onSubmitClick = function() {
vm.resetErrors();
Expand All @@ -94,33 +94,15 @@ module.exports = function(ngModule) {
}, function (error) {
if(error && error.data){
$scope.registerErrors = apiService.parseErrors(error.data);
if($scope.registerErrors.indexOf("EIN is already registered") > -1){
vm.einError = true;
}
if($scope.registerErrors.indexOf("Unable to validate reCaptcha Response") > -1){
vm.reCaptchaError = true;
}
if(some($scope.registerErrors, function(error) { return error.indexOf("is already taken") > -1;})) {
vm.emailAddressError = true;
}
if($scope.registerErrors.indexOf("The Email field is required.") > -1){
vm.emailAddressRequired = true;
}
if($scope.registerErrors.indexOf("The Password field is required.") > -1){
vm.passwordRequired = true;
}
if($scope.registerErrors.indexOf("The EIN field is required.") > -1){
vm.einRequired = true;
}
if(some($scope.registerErrors, function(error) { return error.indexOf("The field EIN must match") > -1;})) {
vm.invalidEin = true;
}
if($scope.registerErrors.indexOf("The password and confirmation password do not match.") > -1){
vm.passwordsDontMatch = true;
}
if($scope.registerErrors.indexOf("Password does not meet complexity requirements.") > -1){
vm.passwordComplexity = true;
}
vm.einError = $scope.registerErrors.indexOf("EIN is already registered") > -1;
vm.reCaptchaError = $scope.registerErrors.indexOf("Unable to validate reCaptcha Response") > -1;
vm.emailAddressError = some($scope.registerErrors, function(error) { return error.indexOf("is already taken") > -1;});
vm.emailAddressRequired = $scope.registerErrors.indexOf("The Email field is required.") > -1;
vm.passwordRequired = $scope.registerErrors.indexOf("The Password field is required.") > -1;
vm.einRequired = $scope.registerErrors.indexOf("The EIN field is required.") > -1;
vm.invalidEin = some($scope.registerErrors, function(error) { return error.indexOf("The field EIN must match") > -1;});
vm.passwordsDontMatch = $scope.registerErrors.indexOf("The password and confirmation password do not match.") > -1;
vm.passwordComplexity = $scope.registerErrors.indexOf("Password does not meet complexity requirements.") > -1 || some($scope.registerErrors, function(error) { return error.indexOf("Passwords must") > -1;});
} else {
vm.generalRegistrationError = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ describe('userRegistrationFormController', function() {
expect(controller.passwordComplexity).toBe(true);
});

it('submitting registration has an error, Password does not meet complexity requirements. message is displayed', function() {
var controller = userRegistrationFormController();
scope.onSubmitClick();
scope.resetRegCaptcha = function() {};
userRegister.reject({data: {"modelState":{"error":[ "Passwords must"] }}});
scope.$apply();

expect(controller.passwordComplexity).toBe(true);
});

it('submitting registration has an error, log error details', function() {
var controller = userRegistrationFormController();
scope.onSubmitClick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2>Create an Account</h2>
</span>
<input type="email" name="registerEmail" id="registerEmail" placeholder="Email" ng-model="formVals.email" />
</div>
<div class="usa-alert" ng-class="vm.passwordComplexity ? 'usa-alert-error' : 'usa-alert-info'" ng-show="vm.showPasswordHelp">
<div class="usa-alert" ng-class="vm.passwordComplexity ? 'usa-alert-error' : 'usa-alert-info'" ng-show="vm.showPasswordHelp || vm.passwordComplexity">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Passwords must</h3>
<p class="usa-alert-text">
Expand All @@ -68,11 +68,12 @@ <h3 class="usa-alert-heading">Passwords must</h3>
<li><span class="checkmark" ng-class="vm.passwordLower ? 'checked' : ''"></span>Contain at least 1 lowercase leter.</li>
<li><span class="checkmark" ng-class="vm.passwordSpecial ? 'checked' : ''"></span>Contain at least 1 special character.</li>
<li><span class="checkmark" ng-class="vm.passwordNumber ? 'checked' : ''"></span>Contain at least 1 number.</li>
<li><span class="checkmark" ng-class="passwordStrength.score > 2 ? 'checked' : ''"></span>Meets "Good" password strength.</li>
</ul>
</p>
</div>
</div>
<div ng-class="vm.passwordRequired || vm.passwordsDontMatch ? 'usa-input-error' : ''">
<div ng-class="vm.passwordRequired || vm.passwordsDontMatch || vm.passwordComplexity ? 'usa-input-error' : ''">
<label for="registerPassword">Password</label>
<span class="usa-input-error-message" id="input-error-message" role="alert" ng-show="vm.passwordRequired || vm.passwordsDontMatch">
<div ng-show="vm.passwordRequired">
Expand All @@ -95,7 +96,7 @@ <h3 class="usa-alert-heading">Passwords must</h3>
</div>
</div>
</div>
<div ng-class="vm.passwordRequired || vm.passwordsDontMatch ? 'usa-input-error' : ''">
<div ng-class="vm.passwordRequired || vm.passwordsDontMatch || vm.passwordComplexity ? 'usa-input-error' : ''">
<label for="confirmPassword">Confirm Password</label>
<input type="password" name="confirmPassword" id="confirmPassword" placeholder="Confirm Password" ng-model="formVals.confirmPass" ng-focus="vm.showPasswordHelp=true" ng-blur="vm.showPasswordHelp=false" />
</div>
Expand Down

0 comments on commit 72f1727

Please sign in to comment.