'use strict'; angular .module('customerLogin') .component('customerLogin', { templateUrl: 'tmpl/customer-login.html?session=KbclaSjmacidzbiibhccVbDlabHaAhel', controllerAs: 'loginCtrl', controller: ['$rootScope', '$scope', '$routeParams', '$window', '$location', '$kWindow', 'AuthService', 'AUTH_STATUS', CustomerLoginController] }); function CustomerLoginController($rootScope, $scope, $routeParams, $window, $location, $kWindow, AuthService, AUTH_STATUS) { var self = this; self.credentials = { cUsername: '', cPassword: '' }; angular.element(document).ready(function () { $("#cUsername").select(); }); self.changeView = function (view) { $location.path(view); }; self.viewName = "Customer Login"; self.companyLogo = "/WMS-Web-Live/img/company-logo.png"; self.login = function (credentials) { if (self.credentials.cUsername == '' || self.credentials.cPassword == '') { self.showErrorMsg("Login", (self.credentials.cUsername == '') ? 'Please enter a valid username' : 'Please enter a valid password'); } else { AuthService.login(self.credentials).then(function () { if (!AuthService.isAuthorized) { if (AuthService.cAuthStatus == AUTH_STATUS.passExpired) { self.credentials.cUsername = ''; self.credentials.cPassword = ''; self.showErrorMsg("Login", AuthService.cErrorMsg); self.changeView('/resetpassword'); } else if (AuthService.cAuthStatus == AUTH_STATUS.notAuthorized) { self.credentials.cUsername = ''; self.credentials.cPassword = ''; self.showErrorMsg("Login", AuthService.cErrorMsg); } } else { self.credentials.cUsername = ''; self.credentials.cPassword = ''; $('#formLogin').append(''); $scope.$broadcast('ContinueLogin',{action: AuthService.cRedirection}); } }, function () { self.showErrorMsg("Login", "Login Failed"); }); } } $scope.$on('ContinueLogin', function (event, args) { angular.element(document)[0].formLogin.action = args.action; angular.element(document)[0].formLogin.submit(); }); $rootScope.$on('CancelLogin',function(event,args){ AuthService = {}; $window.location.href = '/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p'; }); $rootScope.$on('CancelNewAccount',function(event,args){ AuthService = {}; self.changeView('/login'); //$window.location.href = '/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p'; }); $rootScope.$on('CancelForgottenPwd',function(event,args){ AuthService = {}; self.changeView('/login'); //$window.location.href = '/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p'; }); $rootScope.$on('ReloadLoginPage',function(event,args){ AuthService = {}; $window.location.href = '/cgi-bin/wspd_cgi.sh/WService=WSWMSWebLive/login/customerlogin.p'; }); self.showErrorMsg = function (pcTitle, pcErrorMsg) { 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); }; }], resolve: { message: function () { return pcErrorMsg; } } }); } }