You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
wastesortingserver/admin/Manager.php

98 lines
4.0 KiB

<?php
//管理员后台登陆
require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/head.php";
getMenu("管理员登陆");
require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Alert.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Login.php";
if (!check_login()) {
if (empty($_REQUEST)) {
echo <<<EOF
<!DOCTYPE html>
<html lang="zh">
<script>
$(function() {
Array.prototype.filter.call($("form.needs-validation"), function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
})
</script>
<body>
<div class="container py-5">
<div class="d-flex justify-content-center align-items-center w-100">
<form class="col-6 needs-validation" novalidate method="post" action="/admin/Manager.php">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">管理员账号</span>
</div>
<input type="text" class="form-control" placeholder="管理员账号" name="manager_name" required>
<div class="invalid-feedback">
管理员账号不为空
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">管理员密码</span>
</div>
<input type="password" class="form-control" placeholder="管理员密码" name="manager_pwd" required>
<div class="invalid-feedback">
管理员密码不为空
</div>
</div>
<button class="btn btn-block btn-info">提交</button>
</form>
</div>
</div>
</body>
</html>
EOF;
}
//else if (!empty($_COOKIE["login_token"]) and !empty($_COOKIE["manager_name"])) {
// $manager_result = new QueryManager();
// DbUtil::query("select * from manager where manager_name=?", $manager_result, array($_COOKIE["manager_name"]));
//// 验证cookie身份信息有效性
// if (empty($manager_result) or $_COOKIE["login_token"] != $manager_result->getManagerResult()->loginToken()) {
// setcookie("manager_name", "", time() - 3600);
// setcookie("login_token", "", time() - 3600);
// error_res("非法验证,请重新登陆", "/admin/Manager.php");
// } else {
// try {
// update_token($manager_result,"您已登录,自动跳转到首页");
// } catch (Exception $e) {
// error($e);
// error_res("管理员身份验证异常,请联系管理员", "/admin/Manager.php");
// }
//
// }
//}
else if (empty($_POST["manager_name"])) {
error_res(array("status" => false, "msg" => "管理员不能为空"), "/admin/Manager.php");
} else if (empty($_POST["manager_pwd"])) {
error_res(array("status" => false, "msg" => "管理员密码不能为空"), "/admin/Manager.php");
} else {
$manager_result = new QueryManager();
DbUtil::query("select * from manager where manager_name=? and manager_pwd=?", $manager_result, array($_POST["manager_name"], md5($_POST["manager_pwd"])));
if (empty($manager_result->getManagerResult())) {
error_res("登陆失败,管理员或密码错误", "/admin/Manager.php");
} else {
update_token($manager_result, "验证成功,自动跳转到首页");
setcookie("manager_name", $manager_result->getManagerResult()->getManagerName(), time() + 60 * 15, "/");
}
}
}