(function () { "use strict"; angular .module('codeAPLEBOX.client.user.customerLogin') .controller('customerLoginController', customerLoginController); /* @ngInject */ function customerLoginController($state, appConfig, $log, Auth, $cookies, ADMIN_WEB_API) { var vm = this; // ======================================================================= // 초기데이터 // ======================================================================= // ======================================================================= // Angularjs Function // ======================================================================= /* vm.goCustomerHome = function(){ $state.go('customer.home'); }*/ vm.goEmployeeLogin = function(){ $state.go('main.employeeLogin'); } vm.goNewMember = function(){ $state.go('main.customerjoinstep1'); } vm.goCustomerfindpassword = function(){ $state.go('main.customerfindpassword'); } vm.customerLogin = function(){ if(vm.accountID == null || vm.password == null || vm.accountID == "" || vm.password == ""){ alert("계정을 확인해주세요.") return; }else{ Auth.login_customer({ accountID: vm.accountID, password: vm.password }).then(function (info) { if (info.infoCode == '1') { //no register vm.errorMessage = '등록되지 않은 사용자입니다.'; alert(vm.errorMessage) return; } else if (info.infoCode == '2') { //wrong password vm.errorMessage = '아이디 또는 비밀번호가 잘못되었습니다.'; alert(vm.errorMessage) return; } else if (info.infoCode == '4') { //wrong password vm.errorMessage = '사용할 수 없는 계정입니다. 관리자에게 문의해 주세요.'; alert(vm.errorMessage) return; } else if (info.infoCode == '3') { //다른기기 접속 vm.errorMessage = '다른 기기에서 접속중입니다. \n이 기기에서 로그인 하시겠습니까?'; var check = confirm(vm.errorMessage); // true: 다른 기기 로그아웃, 로그인 if(check){ ADMIN_WEB_API.destroyDuplicateIp_customer({ accountID: vm.accountID }).then(function(result){ Auth.login_customer({ accountID: vm.accountID, password: vm.password }).then(function(result){ Auth.getCurrentUser() .then(function(result){ var customerInfo = result.data; if(customerInfo == null){ alert("아이디와 비밀번호를 확인해주세요.") return; } $cookies.putObject("customerInfo", customerInfo); $state.go("customer.home") }).catch(function(errorMessage){ $log.debug(err); }); }).catch(function(err){ $log.debug(err); }) }).catch(function(err){ $log.debug(err); }) }else{ return; } }else{ Auth.getCurrentUser() .then(function(result){ var customerInfo = result.data; if(customerInfo == null){ alert("아이디와 비밀번호를 확인해주세요.") return; } $cookies.putObject("customerInfo", customerInfo); $state.go("customer.home") }).catch(function(errorMessage){ $log.debug(errorMessage); }); } }).catch(function (err) { $log.debug(err); }); } } // ======================================================================= // Common API // ======================================================================= } })();