OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2022-01-07 911e65ca7d4f47ec18212375b4eb479c1c40acbe
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
144
145
/**
 * Created by wisestone on 2017-12-15.
 */
'use strict';
 
define([
        'app',
        'angular'
    ],
    function (app, angular) {
        app.controller('userAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', 'SweetAlert', '$filter', 'Auth', '$state',
            function ($scope, $rootScope, $log, $resourceProvider, User, SweetAlert, $filter, Auth, $state) {
 
                $scope.fn = {
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,  //  폼 체크
                    onFileSelect : onFileSelect, //  프로필 업로드
                    autoHyphenPhone : autoHyphenPhone // 연락처 입력시 하이픈 자동 입력
                };
 
                $scope.vm = {
                    form : {
                        name : "",
                        account : "",
                        password : "",
                        passwordConfirm : "",
                        phone : "",
                        profileImage : null,
                        status : "01",
                        workspaceName : "myWorkSpace",
                        profileImageName : null,
                        agreeTerm : false,
                        licensekey : ""
                    }
                };
 
                function onFileSelect($files) {
                    $scope.vm.form.profileImage = $files;
 
                    if ($rootScope.isDefined($files)) {
                        $scope.vm.form.profileImageName = $files[0].name;
                    }
                    else {
                        $scope.vm.form.profileImageName = "";
                    }
                }
 
                //  연락처 입력시 하이픈 자동 입력
                function autoHyphenPhone() {
                    // 핸드폰 번호 조건
                    var str = $scope.vm.form.phone
                    str.replace(/^[0-9]/g, '');
                    var tmp = '';
                    
                    if (str.length < 4) {
                        return str;
                    } else if (str.length < 7) {
                        tmp += str.substr(0, 3);
                        tmp += '-';
                        tmp += str.substr(3);
                        $scope.vm.form.phone = tmp;
                    } else if (str.length < 11) {
                        tmp += str.substr(0, 3);
                        tmp += '-';
                        tmp += str.substr(3, 3);
                        tmp += '-';
                        tmp += str.substr(6);
                        $scope.vm.form.phone = tmp;
                    } else {
                        tmp += str.substr(0, 3);
                        tmp += '-';
                        tmp += str.substr(3, 4);
                        tmp += '-';
                        tmp += str.substr(7);
                        $scope.vm.form.phone = tmp;
                    }
                    return str
                }
 
                // 폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
 
                    if ($scope.vm.form.password.length < 4) {
                        return true;
                    }
 
                    if ($scope.vm.form.passwordConfirm.length < 4) {
                        return true;
                    }
 
                    if ($scope.vm.form.password !== $scope.vm.form.passwordConfirm) {
                        return true;
                    }
 
                    // if (!$scope.vm.form.agreeTerm) {
                    //     return true;
                    // }
 
                    return false;
                }
 
                // 폼 전송
                function formSubmit() {
                    $rootScope.spinner = true;  //  프로그래스 바
 
                    var content = angular.copy($scope.vm.form);
                    content.name = $rootScope.preventXss(content.name);
                    content.workspaceName = $rootScope.preventXss(content.workspaceName);
                    content.password = CryptoJS.SHA512(content.password).toString();
                    content.language = $rootScope.language; //  기본 언어
                    content.phone = content.phone.replace(/\-/g,'');    // 전화번호를 보낼땐 하이픈을 제거해서 DB에 저장
 
                    User.add({
                        method : "POST",
                        file : $scope.vm.form.profileImage,
                        //      data 속성으로 별도의 데이터 전송
                        fields : {
                            content : content
                        },
                        fileFormDataName : "file"
                    }).then(function (result) {
                        if (result.data.message.status === "success") {
                            Auth.login({
                                account : $rootScope.encryption($scope.vm.form.account),
                                password : CryptoJS.SHA512($scope.vm.form.password).toString()
                            }).then(function () {
                                $rootScope.spinner = false;
                                $rootScope.back();
                            }).catch(function () {
                                $rootScope.spinner = false;
                                $state.go("login");
                            });
                        }
                        else {
                            SweetAlert.swal($filter("translate")("users.failedToCreateUser"), result.data.message.message, "error"); // "사용자 생성 실패"
                            $rootScope.spinner = false;
                        }
                    });
                }
 
            }]);
    });