Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amfirnas authored and amfirnas committed Sep 1, 2017
1 parent 830949d commit cddeb28
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 22 deletions.
24 changes: 24 additions & 0 deletions web/src/app/pages/signin/change_password.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<main class="auth-main" style="padding-top:150px;">
<div class="auth-block">
<h1>Change password</h1>
<form class="form-horizontal">
<div class="form-group">
<label for="new_password" class="col-sm-2 control-label">New</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="new_password" ng-model="new_password" placeholder="new password" required>
</div>
</div>
<div class="form-group">
<label for="confirm_password" class="col-sm-2 control-label">Confirm</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="confirm_password" ng-model="confirm_password" placeholder="confirm password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" ng-click="changePassword()" data-ng-disabled="!new_password || !confirm_password" class="btn btn-default btn-auth">Change password</button>
</div>
</div>
</form>
</div>
</main>
4 changes: 2 additions & 2 deletions web/src/app/pages/signin/forgotpwd.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<main class="auth-main" style="padding-top:150px;">
<div class="auth-block">
<h1>Forgot Password</h1>
<form class="form-horizontal">
<form class="form-horizontal" action="#/signin/verify">
<div class="form-group">
<label for="email" class="col-sm-2 control-label">email</label>
<div class="col-sm-10">
Expand All @@ -10,7 +10,7 @@ <h1>Forgot Password</h1>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" ng-click="forgot()" class="btn btn-default btn-auth">Send</button>
<button type="submit" ng-click="forgot()" data-ng-disabled="!username" class="btn btn-default btn-auth">Send</button>
</div>
</div>
</form>
Expand Down
62 changes: 44 additions & 18 deletions web/src/app/pages/signin/signin.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@
ClientId: IG.cognitoClientId
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
//sign in function starts from here

$scope.confirm = function() {
// FIXME: these two declaration
var verificationCode;
var username;

// take verification code, user's input
$scope.values = function() {
window.verificationCode = $scope.verification_code;

};

// get triggered once user provide the email id from forgot password section view
$scope.forgot = function() {

var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

// $rootScope.username = $scope.username;
window.username = $scope.username;

var userData = {
Username: $scope.username,
Expand All @@ -25,42 +40,52 @@

var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);

cognitoUser.confirmRegistration($scope.code, true, function(err, result) {
if (err) {

cognitoUser.forgotPassword({
onSuccess: function(result) {
toastr.success(result.message, 'Success');
},
onFailure: function(err) {
toastr.error(err.message, 'Error');
return;
},
inputVerificationCode: function() {
}
toastr.success(result.message, 'Success');
});

};

$scope.forgot = function() {
// changing password functionality with verification code
$scope.changePassword = function(){

var userData = {
Username: $scope.username,
var new_Password = $scope.new_password;

var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

var userChangeData = {
Username: window.username,
Pool: userPool
};

var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userChangeData);

cognitoUser.forgotPassword({
onSuccess: function(result) {
var verificationCode = window.verificationCode.toString();

cognitoUser.verifyAttribute(window.username.toString(), verificationCode, this,{
onSuccess: function (result) {
toastr.success(result.message, 'Success');
},

onFailure: function(err) {
toastr.error(err.message, 'Error');
},
inputVerificationCode: function() {
var verificationCode = prompt('Please input verification code ', '');
var newPassword = prompt('Enter new password ', '');
cognitoUser.confirmPassword(verificationCode, newPassword, this);
cognitoUser.confirmPassword(verificationCode, new_Password, this);
// $location.href = '#/signin/signin';
}
});

};


// user signin functionality
$scope.signIn = function() {

var authenticationData = {
Expand Down Expand Up @@ -109,5 +134,6 @@

});
};

}
})();
})();
13 changes: 11 additions & 2 deletions web/src/app/pages/signin/signin.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@
})

.state('confirm', {
url: '/signin/confirm',
templateUrl: 'app/pages/signin/confirm.html',
url: '/signin/verify',
templateUrl: 'app/pages/signin/verify.html',
controller: 'SignInCtrl'


})

.state('changePassword', {
url: '/signin/change',
templateUrl: 'app/pages/signin/change_password.html',
controller: 'SignInCtrl'


});

}
})();
18 changes: 18 additions & 0 deletions web/src/app/pages/signin/verify.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<main class="auth-main" style="padding-top:150px;">
<div class="auth-block">
<h1>Verification Code</h1>
<form class="form-horizontal" action="#/signin/change">
<div class="form-group">
<label for="code" class="col-sm-2 control-label">Code</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="code" ng-model="verification_code" placeholder="code" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" ng-click="values()" data-ng-disabled="!verification_code" class="btn btn-default btn-auth">Verify</button>
</div>
</div>
</form>
</div>
</main>

0 comments on commit cddeb28

Please sign in to comment.