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 #94 from AppliedIS/feature-adminroles
Browse files Browse the repository at this point in the history
Reset Password, Change Password, Create/Edit Account Validation
  • Loading branch information
jefferey committed Nov 3, 2016
2 parents f8a1098 + 97c1558 commit 04bfb37
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,60 @@ module.exports = function(ngModule) {

var vm = this;
vm.stateService = stateService;

vm.resetErrors = function() {
vm.savingError = false;
vm.loadingError = false;
}

vm.resetErrors();

if($routeParams.userId !== "create"){
$scope.userId = $routeParams.userId;
vm.isEditAccount = true;
apiService.getAccount(stateService.access_token, $scope.userId).then(function (result) {
var data = result.data;
$scope.formVals = data;
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));
vm.loadingError = true;
});
}
else {
$scope.formVals = {
roles: []
}
}

apiService.getAccount(stateService.access_token, $scope.userId).then(function (result) {
var data = result.data;
$scope.formVals = data;
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error
});

apiService.getRoles(stateService.access_token).then(function (result) {
var data = result.data;
$scope.roles = data;
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error
vm.loadingError = true;
});

vm.submitForm = function() {
vm.resetErrors();
if(vm.isEditAccount){
apiService.modifyAccount(stateService.access_token, $scope.formVals).then(function (result) {
$location.path("/");
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));
//TODO: inform user of error
$scope.savingErrors = apiService.parseErrors(error.data);
vm.savingError = true;
});
} else {
apiService.createAccount(stateService.access_token, $scope.formVals).then(function (result) {
$location.path("/");
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));
//TODO: inform user of error
$scope.savingErrors = apiService.parseErrors(error.data);
vm.savingError = true;
});
}
}


vm.toggleRole = function(role) {
var idx = vm.roleExists(role.id);
if (idx > -1) {
Expand All @@ -75,5 +81,9 @@ module.exports = function(ngModule) {
}
return foundId;
}

vm.cancelClick = function() {
$location.path("/");
}
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@

<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.savingError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while saving the account.
<ul ng-show="savingErrors.length > 0">
<li ng-repeat="error in savingErrors">{{error}}</li>
</u>
</p>
</div>
</div>

<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.loadingError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while loading account.</p>
</div>
</div>

<form class="usa-form" ng-submit="vm.submitForm()">
<div>
<h2 ng-if="vm.isEditAccount">Edit Account</h2>
Expand All @@ -14,13 +33,15 @@ <h2 ng-if="!vm.isEditAccount">Create Account</h2>
</ul>
</div>
<div ng-if="vm.isEditAccount">
<div><label>Password Last Changed</label><span am-time-ago="formVals.lastPasswordChangedDate | amUtc"></span></div>
<div><label>Password Last Changed</label><span am-time-ago="formVals.lastPasswordChangedDate"></span></div>
<div><label>Email Confirmed</label><span>{{formVals.emailConfirmed}}</span></div>
<div ng-if="formVals.lockoutEndDateUtc !== null"><label>Account Locked</label>End Date: <span am-time-ago="formVals.lockoutEndDateUtc | amUtc"></div>
<div class="loginbtn"><button type="submit">Update Account</button></div>
<div class="form-spaced-div">
<span><button type="submit">Update Account</button></span><button class="grey-button" ng-click="vm.cancelClick()">Cancel</button>
</div>
</div>
<div ng-if="!vm.isEditAccount">
<div class="loginbtn"><button type="submit">Create Account</button></div>
<div ng-if="!vm.isEditAccount" class="form-spaced-div">
<span><button type="submit">Create Account</button></span><button class="grey-button" ng-click="vm.cancelClick()">Cancel</button>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module.exports = function(ngModule) {

var vm = this;
vm.stateService = stateService;
vm.loadingError = false;

apiService.getAccounts(stateService.access_token).then(function (result) {
var data = result.data;
$scope.accounts = data;
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error
vm.loadingError = true;
});

vm.editAccountClick = function(userId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.loadingError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while loading accounts.</p>
</div>
</div>

<table class="usa-table-borderless"
ng-show="accounts.length">
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module.exports = function(ngModule) {

var vm = this;
vm.stateService = stateService;

vm.resetErrors = function() {
vm.changePasswordError = false;
vm.changePasswordSuccess = false;
}

vm.resetErrors();

$scope.formVals = {
'currentPass': '',
Expand All @@ -15,18 +22,18 @@ module.exports = function(ngModule) {
};

$scope.onSubmitClick = function() {
apiService.changePassword(stateService.user.loginEmail, $scope.formVals.currentPass, $scope.formVals.newPass, $scope.formVals.confirmPass ).then(function (result) {
vm.resetErrors();
apiService.changePassword(stateService.access_token, $scope.formVals.email, $scope.formVals.currentPass, $scope.formVals.newPass, $scope.formVals.confirmPass).then(function (result) {
var data = result.data;

//TODO: provide user with confirmation

$location.path("/");
stateService.user.loginEmail = '';
$scope.formVals.currentPass = '';
$scope.formVals.newPass = '';
$scope.formVals.confirmPass = '';
vm.changePasswordSuccess = true;
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error

$location.path("/");
$scope.changePasswordErrors = apiService.parseErrors(error.data);
vm.changePasswordError = true;
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
<div ng-if="!stateService.user.email">
<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.changePasswordError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while changing your password.
<ul ng-show="changePasswordErrors.length > 0">
<li ng-repeat="error in changePasswordErrors">{{error}}</li>
</u>
</p>
</div>
</div>

<div class="usa-alert usa-alert-success" role="alert" ng-show="vm.changePasswordSuccess">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Password Changed</h3>
<p class="usa-alert-text">Your password has be changed. Please <a href="/">Login</a> with your new password.</p>
</div>
</div>

<div ng-if="!stateService.user.email" ng-class="vm.changePasswordError ? 'usa-input-error' : ''">
<label for="userName">Email</label>
<input name="userName" id="userName" type="email" placeholder="Email" ng-model="formVals.email" />
</div>
<div>
<div ng-class="vm.changePasswordError ? 'usa-input-error' : ''">
<label for="userName">Current Password</label>
<input type="password" name="password" id="password" placeholder="Current Password" ng-model="formVals.currentPass" />
</div>
<div>
<div ng-class="vm.changePasswordError ? 'usa-input-error' : ''">
<label for="newPass">New Password</label>
<input type="password" name="newPass" id="newPass" placeholder="New Password" ng-model="formVals.newPass" />
</div>
<div>
<div ng-class="vm.changePasswordError ? 'usa-input-error' : ''">
<label for="confirmPass">Confirm Password</label>
<input type="password" name="confirmPass" id="confirmPass" placeholder="Confirm Password" ng-model="formVals.confirmPass" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ module.exports = function(ngModule) {
var vm = this;
vm.stateService = stateService;

vm.resetErrors = function() {
vm.forgotPasswordError = false;
vm.forgotPasswordSuccess = false;
vm.resetPasswordError = false;
vm.resetPasswordSuccess = false;
}

vm.resetErrors()

vm.resetPasswordVerificationUrl = $location.absUrl();
vm.resetPasswordVerificationCode = $location.search().code;
vm.resetPasswordVerificationUserId = $location.search().userId;
Expand All @@ -18,42 +27,33 @@ module.exports = function(ngModule) {
'confirmPass': ''
};


$scope.onSubmitClick = function() {

vm.resetErrors();
apiService.resetPassword($scope.formVals.email, vm.resetPasswordVerificationUrl).then(function (result) {
var data = result.data;

//TODO: provide user with confirmation

$location.path("/");
vm.forgotPasswordSuccess = true;
$scope.formVals.email = '';
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error

$location.path("/");
vm.forgotPasswordError = true;
});
}

$scope.onVerifySubmitClick = function() {

$location.search('code', null);
$location.search('userId', null);
vm.resetErrors();

apiService.verifyResetPassword(vm.resetPasswordVerificationUserId, $scope.formVals.newPass, $scope.formVals.confirmPass, vm.resetPasswordVerificationCode).then(function (result) {
var data = result.data;

//TODO: provide user with confirmation

$location.path("/");
vm.resetPasswordSuccess = true;
$scope.formVals.newPass = '';
$scope.formVals.confirmPass = '';
}, function (error) {
console.log(error.statusText + (error.data && error.data.error ? ': ' + error.data.error + ' - ' + error.data.error_description : ''));

//TODO: inform user of error

$location.path("/");
$scope.resetPasswordErrors = apiService.parseErrors(error.data);
vm.resetPasswordError = true;
});
}


});
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@

<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.forgotPasswordError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while connecting to the server. Please try again later if the error persists.</p>
</div>
</div>

<div class="usa-alert usa-alert-success" role="alert" ng-show="vm.forgotPasswordSuccess">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Email Sent</h3>
<p class="usa-alert-text">If your the email address matches our records, you should recieve an email with a link to reset your password.</p>
</div>
</div>

<div class="usa-alert usa-alert-error" role="alert" ng-show="vm.resetPasswordError">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Error</h3>
<p class="usa-alert-text">An error occurred while reseting your password.
<ul ng-show="resetPasswordErrors.length > 0">
<li ng-repeat="error in resetPasswordErrors">{{error}}</li>
</u>
</p>
</div>
</div>

<div class="usa-alert usa-alert-success" role="alert" ng-show="vm.resetPasswordSuccess">
<div class="usa-alert-body">
<h3 class="usa-alert-heading">Password Reset</h3>
<p class="usa-alert-text">Your password has be reset. Please <a href="/">Login</a> with your new password.</p>
</div>
</div>

<form ng-submit="onSubmitClick()" ng-show="!vm.isResetPasswordVerificationRequest">
<h2>Forgot Password</h2>
<div>
<div ng-class="vm.forgotPasswordError ? 'usa-input-error' : ''">
<label for="userName">Email</label>
<input name="userName" id="userName" type="email" placeholder="Email" ng-model="formVals.email" />
</div>
<div class="loginbtn"><button type="submit">Email Reset Link</button></div>
<div><button type="submit">Email Reset Link</button></div>
</form>

<form ng-submit="onVerifySubmitClick()" ng-show="vm.isResetPasswordVerificationRequest">
<h2>Reset Password</h2>
<div>
<div ng-class="vm.resetPasswordError ? 'usa-input-error' : ''">
<label for="newPass">New Password</label>
<input type="password" name="newPass" id="newPass" placeholder="New Password" ng-model="formVals.newPass" />
</div>
<div>
<div ng-class="vm.resetPasswordError ? 'usa-input-error' : ''">
<label for="confirmPass">Confirm Password</label>
<input type="password" name="confirmPass" id="confirmPass" placeholder="Confirm Password" ng-model="formVals.confirmPass" />
</div>
<div class="loginbtn"><button type="submit">Reset Password</button></div>

<div><button type="submit">Reset Password</button></div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ <h2>Section 14(c) Certificate Application</h2>
<button class="save-button"
onclick="window.location='#/section/assurances';">Continue Application</button>
</div>
<div>
<a href="#/changePassword">Change Password</a>
</div>
</div>
</div>
<div ng-if="stateService.user.email">
<a href="#/changePassword">Change Password</a>
</div>
<div class="usa-grid"
ng-if="!stateService.user.email">
<div class="usa-width-one-half">
Expand Down
Loading

0 comments on commit 04bfb37

Please sign in to comment.