hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/db/DBOper.php";
include_once "/language/lang.php";
 
function CreateSuperAdmin()
{
    global $msg;
 
    $UserAccount = $_POST["UserAccount"];
    $Psw = $_POST["Psw"];
    $PswConfirm = $_POST["PswConfirm"];
 
    if (!$UserAccount || !$Psw) {
        $msg = "账号密码不能为空!";
        \Logging\LogError($msg);
        return;
    }
 
    if ($Psw != $PswConfirm) {
        $msg = "账号密码不一致!";
        \Logging\LogError($msg);
        return;
    }
 
    if (!\DBOper\FindOne("GMTUser", array("UserLV" => \User\UserLV::ADMIN_SUPER), $userData)) {
        $msg = "数据异常!";
        \Logging\LogError($msg);
        return;
    }
 
    if (isset($userData)) {
        $msg = "已经存在超级管理员账号,不能重复创建!";
        \Logging\LogError($msg);
        return true;
    }
 
    $Psw = \Commfunc\GetEncodePsw($Psw);
    if (!$Psw) {
        $msg = "密码异常!";
        \Logging\LogError($msg);
        return;
    }
 
    $OrganizationList = \CommFunc\GetAllOrganization();
    if (!isset($OrganizationList) || count($OrganizationList) < 0) {
        $msg = "没有配置组织!";
        \Logging\LogError($msg);
        return;
    }
 
    if (!\DBOper\Insert("GMTUser", array(
        "UserAccount" => $UserAccount,
        "Psw" => $Psw,
        "UserLV" => \User\UserLV::ADMIN_SUPER,
        "Organization" => $OrganizationList[0], #超管默认属于第一个组织
        "CreateTime" => date("Y-m-d H:i:s")
    ))) {
        $msg = "创建失败!";
        \Logging\LogError($msg);
        return;
    }
 
    \Logging\LogInfo("创建成功!" . $UserAccount);
    return 1;
}
 
\Logging\CreateLogging("account.super.php");
\Logging\LogInfo("_POST: " . print_r($_POST, true));
 
$msg = "";
$ok = 0;
if (array_key_exists('UserAccount', $_POST)) {
    $ok = CreateSuperAdmin();
} else {
    if (\DBOper\FindOne("GMTUser", array("UserLV" => \User\UserLV::ADMIN_SUPER), $userData) && isset($userData)) {
        $ok = 2;
        $msg = "已经存在超级管理员账号,不用创建!";
        \Logging\LogError($msg);
    }
}
 
if ($msg) {
    echo "<script>alert('" . $msg . "')</script>";
}
 
// echo $ok;
if ($ok > 0) {
    header("Location:/Account/login.php?superok=" . $ok);
    exit;
}
 
?>
 
<html>
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>GM工具</title>
    <link rel="stylesheet" type="text/css" href="/css/tableform.css">
</head>
 
<body>
    <div class="divForm">
        <form id="super" name="super" action="super.php" method="post">
            <table id="tt" class="formTable">
                <caption>
                    <b>请先创建超级管理员</b><br /><br />
                </caption>
                <tr>
                    <td class="formTableTDName">超级管理员账号: </td>
                    <td class="formTableTDValue">
                        <input type="text" id="UserAccount" name="UserAccount" value="" placeholder="至少3个字符" />
                    </td>
                </tr>
                <tr>
                    <td class="formTableTDName">密码: </td>
                    <td class="formTableTDValue">
                        <input type="password" id="Psw" name="Psw" value="" placeholder="" />
                    </td>
                </tr>
                <tr>
                    <td class="formTableTDName">重复输入密码: </td>
                    <td class="formTableTDValue">
                        <input type="password" id="PswConfirm" name="PswConfirm" value="" placeholder="" />
                    </td>
                </tr>
                <tr>
                    <td class="formTableTDName"></td>
                    <td class="formTableTDValue">
                        <input type="submit" name="submit" value="提交" onclick="return CheckSubmit();" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
 
    <script type="text/javascript">
        function CheckSubmit() {
            if (!document.getElementById("UserAccount").value || document.getElementById("UserAccount").value.length < 3) {
                alert("账号不符合要求!");
                document.getElementById('UserAccount').focus();
                return false;
            }
            if (!document.getElementById("Psw").value) {
                alert("密码不能为空!");
                document.getElementById('Psw').focus();
                return false;
            }
            if (!document.getElementById("PswConfirm").value) {
                alert("密码不能为空!");
                document.getElementById('PswConfirm').focus();
                return false;
            }
            if (document.getElementById("Psw").value != document.getElementById("PswConfirm").value) {
                alert("密码不一致!");
                document.getElementById('PswConfirm').focus();
                return false;
            }
            return true;
        }
    </script>
</body>
 
<style type="text/css">
    .divForm {
        position: absolute;
        width: 400px;
        height: 300px;
        text-align: center;
        top: 50%;
        left: 50%;
        /* width heigh 一半 */
        margin-left: -200px;
        margin-top: -150px;
    }
</style>
 
</html>