forked from pplulee/appleid_auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_edit.php
277 lines (277 loc) · 16.5 KB
/
account_edit.php
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
include("header.php");
global $conn;
if (isset($_POST['submit'])) {
switch ($_GET['action']) {
case "add":
{
if (get_account_id($_POST['username']) != -1) {
alert("warning", "账号已存在", 2000, "account.php");
exit;
}
$stmt = $conn->prepare("INSERT INTO account (username, password, remark, dob, question1, answer1,question2,answer2,question3,answer3,owner,share_link,check_interval,frontend_remark,message,enable_check_password_correct, enable_delete_devices)
VALUES (:username,:password,:remark,:dob,:question1,:answer1,:question2,:answer2,:question3,:answer3,:owner,:share_link,:check_interval,:frontend_remark,:message,:enable_check_password_correct,:enable_delete_devices);");
$stmt->execute([
'username' => $_POST['username'],
'password' => $_POST['password'],
'remark' => $_POST['remark'],
'dob' => $_POST['dob'],
'question1' => $_POST['question1'],
'answer1' => $_POST['answer1'],
'question2' => $_POST['question2'],
'answer2' => $_POST['answer2'],
'question3' => $_POST['question3'],
'answer3' => $_POST['answer3'],
'owner' => $_SESSION['user_id'],
'share_link' => $_POST['share_link'],
'check_interval' => $_POST['check_interval'],
'frontend_remark' => $_POST['frontend_remark'],
'message' => "未执行任务",
'enable_check_password_correct' => isset($_POST['enable_check_password_correct']) ? 1 : 0,
'enable_delete_devices' => isset($_POST['enable_delete_devices']) ? 1 : 0
]);
alert("success", "添加成功", 2000, "account.php");
exit;
}
case "edit":
{
$account = new account($_GET['id']);
if ($account->owner == $_SESSION['user_id'] || $account->id) {
$account->update(
$_POST['username'],
$_POST['password'],
$_POST['remark'],
$_POST['dob'],
$_POST['question1'],
$_POST['answer1'],
$_POST['question2'],
$_POST['answer2'],
$_POST['question3'],
$_POST['answer3'],
$_SESSION['user_id'],
$_POST['share_link'],
$_POST['check_interval'],
$_POST['frontend_remark'],
isset($_POST['enable_check_password_correct']) ? 1 : 0,
isset($_POST['enable_delete_devices']) ? 1 : 0);
alert("success", "修改成功", 2000, "account.php");
} else {
alert("error", "修改失败", 2000, "account.php");
}
exit;
}
default:
{
alert("error", "未知错误", 2000, "account.php");
exit;
}
}
}
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case "delete":
{
if (!isset($_GET['id'])) {
alert("error", "缺少参数", 2000, "account.php");
exit;
}
$account = new account($_GET['id']);
if ($account->owner == $_SESSION['user_id'] || $account->id) {
$account->delete();
alert("success", "删除成功", 2000, "account.php");
} else {
alert("error", "删除失败", 2000, "account.php");
}
exit;
}
case "add":
{
$share_link = random_string(12);
$width = isMobile() ? "auto" : "60%";
echo "<div class='container' style='margin-top: 2%; width: $width;'>
<div class='card border-dark'>
<h4 class='card-header bg-primary text-white text-center'>添加账号</h4>
<form action='' method='post' style='margin: 20px;'>
<div class='input-group mb-3'>
<span class='input-group-text' id='id'>用户名</span>
<input type='text' class='form-control' name='username' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='password'>密码</span>
<input type='text' class='form-control' name='password' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='remark'>备注</span>
<input type='text' class='form-control' name='remark' autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='frontend_remark'>前端备注</span>
<input type='text' class='form-control' name='frontend_remark' placeholder='账号的说明,在分享页显示' autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='dob'>生日</span>
<input type='text' class='form-control' name='dob' placeholder='格式:mmddyyyy' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question1'>问题1</span>
<input type='text' class='form-control' name='question1' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer1'>答案1</span>
<input type='text' class='form-control' name='answer1' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question2'>问题2</span>
<input type='text' class='form-control' name='question2' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer2'>答案2</span>
<input type='text' class='form-control' name='answer2' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question3'>问题3</span>
<input type='text' class='form-control' name='question3' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer3'>答案3</span>
<input type='text' class='form-control' name='answer3' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question2'>分享代码</span>
<input type='text' class='form-control' name='share_link' value='$share_link' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='check_interval'>检查间隔</span>
<input type='number' class='form-control' name='check_interval' required autocomplete='off' placeholder='单位:分钟' value='10'>
</div>
<div class='input-group mb-3'>
<div class='form-check form-switch'>
开启密码正确检测<input class='form-check-input' type='checkbox' name='enable_check_password_correct'>
若密码错误则自动修改密码
</div>
</div>
<div class='input-group mb-3'>
<div class='form-check form-switch'>
开启删除设备<input class='form-check-input' type='checkbox' name='enable_delete_devices'>
</div>
</div>
<input type='submit' name='submit' class='btn btn-primary btn-block' value='添加'>
</form>
</div>
</div>";
exit;
}
case "edit":
{
if (!isset($_GET['id'])) {
alert("error", "缺少参数", 2000, "account.php");
exit;
}
$account = new account($_GET['id']);
if ($account->id == -1) {
alert("error", "账号不存在", 2000, "account.php");
exit;
}
if ($account->owner == $_SESSION['user_id']) {
$width = isMobile() ? "auto" : "60%";
$question1 = array_keys($account->question)[0];
$question2 = array_keys($account->question)[1];
$question3 = array_keys($account->question)[2];
$answer1 = $account->question[$question1];
$answer2 = $account->question[$question2];
$answer3 = $account->question[$question3];
$check_interval = $account->check_interval;
$check_password_checked = $account->enable_check_password_correct ? "checked" : "";
$delete_devices_checked = $account->enable_delete_devices ? "checked" : "";
echo "<div class='container' style='margin-top: 2%; width: $width;'>
<div class='card border-dark'>
<h4 class='card-header bg-primary text-white text-center'>编辑账号</h4>
<form action='' method='post' style='margin: 20px;'>
<div class='input-group mb-3'>
<span class='input-group-text' id='username'>用户名</span>
<input type='text' class='form-control' name='username' required autocomplete='off' value='$account->username'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='password'>密码</span>
<input type='text' class='form-control' name='password' required autocomplete='off' value='$account->password'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='remark'>备注</span>
<input type='text' class='form-control' name='remark' autocomplete='off' value='$account->remark'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='frontend_remark'>前端备注</span>
<input type='text' class='form-control' name='frontend_remark' placeholder='账号的说明,在分享页显示' autocomplete='off' value='$account->frontend_remark'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='dob'>生日</span>
<input type='text' class='form-control' name='dob' placeholder='格式:mmddyyyy' required autocomplete='off' value='$account->dob'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question1'>问题1</span>
<input type='text' class='form-control' name='question1' required autocomplete='off' value='$question1'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer1'>答案1</span>
<input type='text' class='form-control' name='answer1' required autocomplete='off' value='$answer1'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question2'>问题2</span>
<input type='text' class='form-control' name='question2' required autocomplete='off' value='$question2'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer2'>答案2</span>
<input type='text' class='form-control' name='answer2' required autocomplete='off' value='$answer2'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='question3'>问题3</span>
<input type='text' class='form-control' name='question3' required autocomplete='off' value='$question3'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='answer3'>答案3</span>
<input type='text' class='form-control' name='answer3' required autocomplete='off' value='$answer3'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='share_link'>分享代码</span>
<input type='text' class='form-control' name='share_link' value='$account->share_link' required autocomplete='off'>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='last_check'>上次检查</span>
<input type='text' class='form-control' name='share_link' value='$account->last_check' required disabled>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='message'>状态</span>
<input type='text' class='form-control' name='message' value='$account->message' required autocomplete='off' disabled>
</div>
<div class='input-group mb-3'>
<div class='form-check form-switch'>
开启密码正确检测<input class='form-check-input' type='checkbox' name='enable_check_password_correct' $check_password_checked>
</div>
</div>
<div class='input-group mb-3'>
<div class='form-check form-switch'>
开启删除设备<input class='form-check-input' type='checkbox' name='enable_delete_devices' $delete_devices_checked>
</div>
</div>
<div class='input-group mb-3'>
<span class='input-group-text' id='check_interval'>检查间隔</span>
<input type='number' class='form-control' name='check_interval' placeholder='单位:分钟' required autocomplete='off' value='$check_interval'>
</div>
<input type='submit' name='submit' class='btn btn-primary btn-block' value='保存'>
</form>
</div>
</div>";
} else {
alert("error", "修改失败", 2000, "account.php");
}
exit;
}
default:
{
alert("error", "未知错误", 2000, "account.php");
exit;
}
}
} else {
alert("error", "缺少参数", 2000, "account.php");
}