-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount.php
More file actions
183 lines (180 loc) · 6.34 KB
/
account.php
File metadata and controls
183 lines (180 loc) · 6.34 KB
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
<!DOCTYPE html>
<?php
require_once __DIR__ . '/vendor/owasp/csrf-protector-php/libs/csrf/csrfprotector.php';
csrfProtector::init();
require('config/config.php');
require("func/account_list.php");
?>
<html lang="zh-Hant-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
require __DIR__ . '/commonhead.php';
?>
<title><?=$C["titlename"]?>/管理帳號</title>
<style type="text/css">
body {
padding-top: 4.5rem;
}
</style>
</head>
<body>
<?php
$showform = true;
if (!$U["islogin"]) {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
此功能需要驗證帳號,請<a href="<?=$C["path"]?>/login/">登入</a>
</div>
<?php
$showform = false;
} else if (isset($_POST["action"])) {
if ($_POST["action"] === "new") {
if (isset($D['account'][$_POST["account"]])) {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已有帳號 <?=htmlentities($_POST["account"])?>
</div>
<?php
} else if ($_POST["password"] === "" || $_POST["name"] === "") {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
密碼及姓名不可為空
</div>
<?php
} else {
$sth = $G["db"]->prepare("INSERT INTO `account` (`account`, `password`, `name`) VALUES (:account, :password, :name)");
$sth->bindValue(":account", $_POST["account"]);
$sth->bindValue(":password", password_hash($_POST["password"], PASSWORD_DEFAULT));
$sth->bindValue(":name", $_POST["name"]);
$sth->execute();
$D["account"][$_POST["account"]] = array("account"=>$_POST["account"], "name"=>$_POST["name"]);
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已新增 <?=htmlentities($_POST["name"])?>
</div>
<?php
}
} else {
if ($_POST["password"] !== "") {
if (isset($D['account'][$_POST["account"]])) {
$sth = $G["db"]->prepare("UPDATE `account` SET `password` = :password WHERE `account` = :account");
$sth->bindValue(":password", password_hash($_POST["password"], PASSWORD_DEFAULT));
$sth->bindValue(":account", $_POST["account"]);
$sth->execute();
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改 <?=htmlentities($_POST["account"])?> 的密碼
</div>
<?php
} else {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
找不到帳號 <?=htmlentities($_POST["account"])?>
</div>
<?php
}
}
if ($_POST["name"] !== "") {
$sth = $G["db"]->prepare("UPDATE `account` SET `name` = :name WHERE `account` = :account");
$sth->bindValue(":name", $_POST["name"]);
$sth->bindValue(":account", $_POST["account"]);
$sth->execute();
$D["account"][$_POST["account"]]["name"] = $_POST["name"];
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改 <?=htmlentities($_POST["account"])?> 的姓名
</div>
<?php
}
}
} else if (isset($_POST["delete"])) {
if (isset($D['account'][$_POST["delete"]])) {
$sth = $G["db"]->prepare("DELETE FROM `account` WHERE `account` = :account");
$sth->bindValue(":account", $_POST["delete"]);
$sth->execute();
unset($D["account"][$_POST["delete"]]);
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已刪除帳號 <?=htmlentities($_POST["delete"])?>
</div>
<?php
}
}
require("header.php");
if ($showform) {
?>
<div class="container">
<h2>管理帳號</h2>
<form action="" method="post">
<div class="table-responsive">
<table class="table">
<tr>
<th>帳號</th>
<th>姓名</th>
<th>刪除</th>
</tr>
<?php
foreach ($D['account'] as $account) {
?>
<tr>
<td><?=htmlentities($account["account"])?></td>
<td><?=htmlentities($account["name"])?></td>
<td>
<button type="submit" name="delete" value="<?=$account["account"]?>" class="btn btn-danger btn-sm"><i class="fa fa-trash" aria-hidden="true"></i> 刪除</button>
</td>
</tr>
<?php
}
?>
</table>
</div>
</form>
<h3>新增/修改</h3>
<form action="" method="post">
<div class="row">
<label class="col-sm-2 form-control-label"><i class="fa fa-user" aria-hidden="true"></i> 帳號</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="account" placeholder="必填">
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label"><i class="fa fa-hashtag" aria-hidden="true"></i> 密碼</label>
<div class="col-sm-10">
<input class="form-control" type="password" name="password" placeholder="新增時必填,不修改留空">
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label"><i class="fa fa-header" aria-hidden="true"></i> 姓名</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="name" placeholder="新增時必填,不修改留空" autocomplete="name">
</div>
</div>
<div class="row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-success" name="action" value="new"><i class="fa fa-plus" aria-hidden="true"></i> 新增</button>
<button type="submit" class="btn btn-success" name="action" value="edit"><i class="fa fa-pencil" aria-hidden="true"></i> 修改</button>
</div>
</div>
</form>
</div>
<?php
}
require("footer.php");
?>
<script type="text/javascript">
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
</body>
</html>