Skip to content

Commit

Permalink
Add reset password flow
Browse files Browse the repository at this point in the history
  • Loading branch information
cassshh committed Jan 25, 2018
1 parent 4d05ca4 commit c9b108a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/resources/public/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ app.config(function ($stateProvider) {
templateUrl: '/app/pages/retard.html',
controller: 'RetardCtrl'
})
.state('reset', {
url: '/reset?token',
templateUrl: '/app/pages/reset.html',
controller: 'ResetCtrl'
})
.state('verify', {
url: '/verify?email&token',
templateUrl: '/app/pages/verify.html',
Expand Down
39 changes: 39 additions & 0 deletions src/main/resources/public/app/js/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
app.controller('ResetCtrl', function (RetardService, $state, $stateParams, $timeout) {

this.submit = () => {
this.loading = true;
this.error = false;
this.success = false;
RetardService.setNewPassword({
email: this.email,
password: this.password,
token: $stateParams.token
}).then((resp) => {
this.loading = false;
this.success = true;
$timeout(() => {
$state.transitionTo('login');
}, 3000);
}).catch((error) => {
this.loading = false;
this.error = true;
});
}

this.showLoading = () => {
return this.loading;
}

this.showForm = () => {
return !this.loading && !this.success;
}

this.showSuccess = () => {
return this.success;
}

this.showError = () => {
return this.error;
}

});
4 changes: 2 additions & 2 deletions src/main/resources/public/app/js/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ app.controller('VerifyCtrl', function (VerifyService, $scope, $state, $statePara
$scope.isLoading = false;
$scope.isFinished = true;
$timeout(() => {
$state.transitionTo('login')
}, 3000);
$state.transitionTo('login');
}, 3000);
}).catch((error) => {
$scope.error = "verification failed."
$scope.isLoading = false;
Expand Down
47 changes: 47 additions & 0 deletions src/main/resources/public/app/pages/reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div flex-xs="" flex-gt-xs="50" style="margin: 0 auto;" ng-controller="ResetCtrl as ctrl">
<h1 class="md-display-2" style="text-align: center;">Grade Master</h1>
<md-card>
<md-toolbar id="override-login-toolbar">
<div class="md-toolbar-tools">
<h2>
<span>Reset password</span>
</h2>
</div>
</md-toolbar>
<md-card-content>
<p ng-if="ctrl.showLoading()">One moment please...</p>
<p ng-if="ctrl.showSuccess()">Your password has been changed. You will be redirected shortly...</p>
<p ng-if="ctrl.showError()">Seems like something went wrong. Check your details or try again later.</p>
<form name="Form" ng-if="ctrl.showForm()">
<md-input-container class="md-block">
<label> Email</label>
<input type="email" name="email" ng-model="ctrl.email" required />
<div ng-messages="Form.email.$error" role="alert" multiple="">
<div class="my-message" ng-message="required">You must supply an email.</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Password</label>
<input type="password" name="password" ng-model="ctrl.password" required password-verify="{{ctrl.confirmPassword}}" />
<div ng-messages="Form.password.$error" role="alert" multiple="">
<div class="my-message" ng-message="required">You must supply a password.</div>
<div class="my-message" ng-message="passwordVerify">No match</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Confirm Password</label>
<input type="password" name="confirmPassword" ng-model="ctrl.confirmPassword" required password-verify="{{ctrl.password}}" />
<div ng-messages="Form.confirmPassword.$error" role="alert" multiple="">
<div class="my-message" ng-message="required">You must supply a password.</div>
<div class="my-message" ng-message="passwordVerify">No match</div>
<div class="error">{{error}}</div>
</div>
</md-input-container>
<div layout="layout">
<md-button type="submit" class="md-raised md-primary pull-right formPage" ng-disabled="!Form.$valid" ng-click="ctrl.submit()"
id="override-login-button">&nbsp Reset password &nbsp</md-button>
</div>
</form>
</md-card-content>
</md-card>
</div>
2 changes: 1 addition & 1 deletion src/main/resources/public/app/services/retard.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ app.factory('RetardService', function (API) {
req: Object.assign({}, API.getUnAuthRequest())
});
};

return this;
});
1 change: 1 addition & 0 deletions src/main/resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<script src="/app/js/directives.js"></script>
<script src="/app/js/register.js"></script>
<script src="/app/js/retard.js"></script>
<script src="/app/js/reset.js"></script>
<script src="/app/js/verify.js"></script>
<script src="/app/js/groups.js"></script>
<script src="/app/js/grades.js"></script>
Expand Down

0 comments on commit c9b108a

Please sign in to comment.