'use strict';
|
|
define(['app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('loginController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'Auth', 'UserHistory', '$uibModal', 'SweetAlert', '$cookies', '$filter',
|
function ($scope, $rootScope, $log, $resourceProvider, Auth, UserHistory, $uibModal, SweetAlert, $cookies, $filter) {
|
$scope.fn = {
|
login: login, // 로그인
|
formCheck: formCheck, // 폼 체크
|
addSocial: addSocial, // 소셜 회원 가입
|
saveAccount: saveAccount, // 아이디 기억하기
|
searchPassword: searchPassword, // 비밀번호 찾기
|
showNotice: showNotice
|
};
|
|
// showNotice();
|
|
function getCookie(name) {
|
var value = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
|
return value? value[2] : null;
|
}
|
|
function showNotice() {
|
var result = getCookie("popupYN");
|
if (result == 'N') {
|
return;
|
}
|
else {
|
$uibModal.open({
|
animation: true,
|
templateUrl: 'views/popup/notice.html',
|
windowClass: 'notice-modal',
|
controller: 'noticeModalController',
|
size: 'lg',
|
backdrop: false
|
});
|
}
|
}
|
|
$scope.vm = {
|
form: {
|
account: $rootScope.isDefined($cookies.get("account")) ? $cookies.get("account") : "",
|
password: "",
|
rememberMe: false
|
},
|
authenticationError: false
|
};
|
|
|
// 아이디 기억하기
|
function saveAccount() {
|
if ($rootScope.isDefined($scope.vm.form.account)) {
|
$cookies.put("account", $scope.vm.form.account);
|
}
|
}
|
|
// 비밀번호 찾기
|
function searchPassword() {
|
$uibModal.open({
|
templateUrl: 'views/user/userPassword.html',
|
size: "md",
|
controller: 'userPasswordController',
|
backdrop: 'static'
|
});
|
}
|
|
// 소셜 회원 가입
|
function addSocial(type) {
|
var url = "";
|
|
switch (type) {
|
case "google" :
|
url = "views/login/google.html";
|
location.href = url;
|
break;
|
case "naver" :
|
url = "views/login/naver.html";
|
location.href = url;
|
break;
|
case "kakao" :
|
url = "views/login/kakao.html";
|
location.href = url;
|
|
break;
|
case "facebook":
|
url = "views/login/facebook.html";
|
location.href = url;
|
break;
|
}
|
}
|
|
// 폼 체크
|
function formCheck() {
|
if (!$rootScope.isDefined($scope.vm.form.account)) {
|
return true;
|
}
|
|
if (!$rootScope.isDefined($scope.vm.form.password)) {
|
return true;
|
}
|
|
if ($scope.vm.form.password.length < 4) {
|
return true;
|
}
|
|
return false;
|
}
|
|
// 로그인
|
function login() {
|
// 엔터키를 사용할 때 폼 체크
|
if ($scope.fn.formCheck()) {
|
return;
|
}
|
|
Auth.login({
|
account: $rootScope.encryption($scope.vm.form.account),
|
password: CryptoJS.SHA512($scope.vm.form.password).toString(),
|
rememberMe: $scope.vm.form.rememberMe
|
}).then(function () {
|
$scope.vm.authenticationError = false;
|
AddLoginHistory();
|
}).catch(function () {
|
$scope.vm.authenticationError = true;
|
});
|
}
|
|
function AddLoginHistory() {
|
UserHistory.addLoginHistory().then(function (result) {
|
if (result.data.message.status === "success") {
|
$rootScope.back();
|
}
|
else {
|
$log.warn('addLoginHistory:', '(failed)insert login history');
|
}
|
});
|
}
|
}
|
]);
|
}
|
);
|