UNPKG

consumerportal

Version:

mydna Custimised for you

167 lines (145 loc) 4.83 kB
/// <reference path="../../includes.ts" /> declare function unescape(es: any): any; module acctMgmtSetPasswordCtrl { interface IAcctMgmtSetPasswordController { passwordStrengthMeter(): any; setPassword(): any; login(): any; } interface IAcctMgmtSetPasswordScope extends angular.IScope { myForm: angular.IFormController } class AcctMgmtSetPasswordController implements IAcctMgmtSetPasswordController { static $inject = [ 'passwordStrengthSrvc', 'apiSrvc', 'mydnaApis', 'errorHandlerSrvc', '$scope', 'locationSrvc', 'authenSrvc', 'appLocalStorage', 'mydnaValues' ]; frm: any; strengthClassName: string; strengthUserText: string; showErrors: any; UrlParameters: any; displayValues:any; setPasswordError:boolean; frmAuthentication:any; errorCode: any; loginAutomatic:boolean; showView:any; constructor( private passwordStrengthSrvc: passwordStrengthSrvc.IPasswordStrengthService, private apiSrvc: apiSrvc.IApiService, private mydnaApis: ImyDNAApis, private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService, private $scope: IAcctMgmtSetPasswordScope, private locationSrvc: locationSrvc.ILocationService, private authenSrvc : authenSrvc.IAuthenService, private storage: app.IAppStorage, private mydnaValues: ImyDNAValues ){ var vm = this; vm.showErrors = false; vm.displayValues = {}; vm.frm = {}; vm.frm.Password = ""; vm.frm.ConfirmPassword = ""; vm.frm.SetPassword=true; vm.UrlParameters = vm.locationSrvc.getParams(); vm.frm.PasswordResetToken = unescape(vm.UrlParameters.token); vm.frm.PasswordResetToken = vm.frm.PasswordResetToken.split(' ').join('+'); vm.frm.Username = vm.UrlParameters.username; vm.displayValues.FirstName = vm.UrlParameters.firstName.toLowerCase(); this.showView = false; vm.setPasswordError = false; vm.frmAuthentication = {}; vm.errorCode = ""; this.loginAutomatic = true; vm.veryfyPasswordLink(); } passwordStrengthMeter() { var strength = this.passwordStrengthSrvc.checkStrength(this.frm.Password); this.strengthClassName = strength.className; this.strengthUserText = strength.userText; } setPassword() { this.setPasswordError = false; this.loginAutomatic = false; this.showErrors = this.showErrors == true ? false : ""; if (this.$scope.myForm.$valid) { this.$scope.$emit("disable-on-save-on"); this.apiSrvc.post_request( this.mydnaApis.ResetPassword , this.frm).then(data => { if (data.data.Succeeded==true){ this.loginAutomatic = true; this.login(); } else{ this.setPasswordError = true; } //this.locationSrvc.goto("/acctmgmt/login", ""); this.$scope.$emit("disable-on-save-off"); }, err => { this.errorHandlerSrvc.errorHandler(err, 'debug', ''); this.$scope.$emit("disable-on-save-off"); }); } else { this.showErrors = true; } } login() { if (this.loginAutomatic) { this.$scope.$emit("disable-on-save-on"); this.frmAuthentication.grant_type = "password"; this.frmAuthentication.client_id = OAuthClientId; this.frmAuthentication.client_secret = OAuthSecret; this.frmAuthentication.scope = OAuthScope; this.frmAuthentication.Username = this.frm.Username; this.frmAuthentication.Password = this.frm.Password; this.frmAuthentication.RememberMe = false; this.apiSrvc.login( OAuthTokenEndPoint , this.frmAuthentication).then(data => { this.storage.removeItem("RememberMe"); this.authenSrvc.setAuthentication(data.data); this.authenSrvc.setAuthenToLocalStorage(data.data); this.locationSrvc.goto('dashboard',""); this.$scope.$emit("disable-on-save-off"); }, err => { if (err.status == 400) { this.errorCode = '400'; } else { this.errorHandlerSrvc.errorHandler(err, 'debug', ''); } this.$scope.$emit("disable-on-save-off"); }); } else { this.showErrors = true; } } veryfyPasswordLink(){ this.$scope.$emit("disable-on-save-on"); this.apiSrvc.post_request_other(this.mydnaApis.VerifyLink,this.UrlParameters).then(data => { this.showView = true; this.$scope.$emit("disable-on-save-off"); }, err => { this.$scope.$emit("disable-on-save-off"); if(err.status==409){ this.locationSrvc.goto('login',""); }else{ this.errorHandlerSrvc.errorHandler(err, 'debug', ''); } }); } } angular.module('app').controller('acctMgmtSetPasswordCtrl', AcctMgmtSetPasswordController); }