'use strict'; angular .module('customerLogin') .component('resetPassword', { templateUrl: 'tmpl/resetpassword/reset-password.html?session=biajHkebqfibdklmczkcBMjhBZcbpjcz', controllerAs: 'resetPwdCtrl', controller: ['$rootScope', '$routeParams', '$scope', '$http', '$location', '$compile', '$kWindow', 'AuthService', 'AUTH_STATUS', ResetPasswordController] }); function ResetPasswordController($rootScope, $routeParams, $scope, $http, $location, $compile, $kWindow, AuthService, AUTH_STATUS) { var self = this; self.cNewPassword = ''; self.cConfPassword = ''; angular.element(document).ready(function () { $("#cNewPassword").select(); }); self.changeView = function (view) { $location.path(view); }; self.viewName = "Reset Password"; self.companyLogo = "/WMS-Web-Live/img/company-logo.png"; self.cPasswordRules = []; AuthService.getPasswordRules().then(function () { if (AuthService.status == AUTH_STATUS.success) self.cPasswordRules = AuthService.passwordrules; else if (AuthService.status == AUTH_STATUS.error) { self.showErrorMsg("Error", AuthService.cErrorMsg, "self.changeView('/login');"); $rootScope.$broadcast('CancelLogin'); } }, function () { }); self.validatePassword = function () { if (self.cNewPassword == "") { self.showErrorMsg("Error", "Please enter a valid password", '$("#cNewPassword").select();'); } else if ((self.cConfPassword == "") || ($.trim(self.cNewPassword) != $.trim(self.cConfPassword))) { self.showErrorMsg("Error", "Password doesn't match confirmation", '$("#cConfPassword").select();'); } else { AuthService.savePassword($.trim(self.cNewPassword), $.trim(self.cConfPassword)).then(function () { if (AuthService.status == AUTH_STATUS.success) { self.cNewPassword = ''; self.cConfPassword = ''; self.showErrorMsg("Confirmation", AuthService.cErrorMsg, "self.cancelLogin();"); } else if (AuthService.status == AUTH_STATUS.error) { self.cNewPassword = ''; self.cConfPassword = ''; self.showErrorMsg("Error", AuthService.cErrorMsg, '$("#cNewPassword").select();'); } }, function () { self.showErrorMsg("Login", "Password change Failed"); $rootScope.$broadcast('CancelLogin'); }); } } self.cancelLogin = function () { $rootScope.$broadcast('CancelLogin'); } self.showErrorMsg = function (pcTitle, pcErrorMsg, pcAction,pcField) { var errorMsgWinHdl = $kWindow.open({ options: { modal: true, title: pcTitle, resizable: true, height: 'auto', width: 400, visible: false }, templateUrl: '../lib/htmls/errormsg.template.html', controllerAs: 'error', controller: ['$windowInstance', 'message', function ErrorMsgContoller($errorMsgWinHdl, pcErrorMsg) { this.message = pcErrorMsg; this.btnOK = function () { $errorMsgWinHdl.close(true); if (pcAction != "") eval(pcAction); if (pcField != "") $("#" + pcField).select(); }; }], resolve: { message: function () { return pcErrorMsg; } } }); } }