OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 3052936fed9166521b0557a36df83eb11a5e51ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'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');
                        }
                    });
                }
            }
        ]);
    }
);