用户登录

test
橙橙楊 5 years ago committed by luffy
parent 01b6ab4367
commit 5b2e678b68
  1. 4
      Log.php
  2. 21
      admin/Login.php
  3. 18
      admin/Manager.php
  4. 12
      admin/Question.php
  5. 16
      admin/WasteSorting.php
  6. 10
      api/BaiduImage.php
  7. 8
      api/QueryText.php
  8. 8
      api/QuestionAPI.php
  9. 4
      baidu/BaiduAiRequest.php
  10. 6
      config.php
  11. 4
      database/DbUtil.php
  12. 12
      database/Query.php
  13. 2
      head.php
  14. 12
      index.php
  15. 15
      static/js/Cookie.js
  16. 15
      test.php

@ -1,6 +1,6 @@
<?php <?php
require_once __ROOT__ . '/vendor/autoload.php'; require_once $_SERVER["DOCUMENT_ROOT"] . '/vendor/autoload.php';
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
@ -30,7 +30,7 @@ function getStream($path)
function getLogger() function getLogger()
{ {
$log = new Logger('name'); $log = new Logger('name');
$log->pushHandler(getStream(__ROOT__ . "/log/run.log")); $log->pushHandler(getStream($_SERVER["DOCUMENT_ROOT"] . "/log/run.log"));
$log->pushHandler(getStream("php://stdout")); // <<< uses a stream $log->pushHandler(getStream("php://stdout")); // <<< uses a stream
return $log; return $log;
} }

@ -21,8 +21,27 @@ function update_token(QueryManager $manager_result, $msg)
// 跳转到首页 // 跳转到首页
if ($_SERVER["SCRIPT_NAME"] == "/admin/Manager.php") { if ($_SERVER["SCRIPT_NAME"] == "/admin/Manager.php") {
info_res($msg, "/admin/Login.php"); info_res($msg, "/",);
echo <<<EOF
<script>
<!--3秒后自动跳转-->
let count=3
let i=setInterval(function() {
if(count-->0){
$("#tip").text(count+"秒后自动跳转");
}else{ }else{
location.href="/"
}
console.info("定时器!!!!!")
},1000)
</script>
<div class="alert alert-info alert-dismissible fade show col-5 m-auto text-center" role="alert">
<strong id="tip"></strong>
</div>
EOF;
} else if ($_SERVER["SCRIPT_NAME"] == "/index.php" && empty($_SERVER["HTTP_REFERER"])) {
response($msg, "alert-info"); response($msg, "alert-info");
} }

@ -1,20 +1,16 @@
<?php <?php
//管理员后台登陆 //管理员后台登陆
if (file_exists("../config.php")) { require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once "../config.php";
} else {
require_once "config.php";
}
require_once __ROOT__ . "/head.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/head.php";
getMenu("管理员登陆"); getMenu("管理员登陆");
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
require_once __ROOT__ . "/Log.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
require_once __ROOT__ . "/admin/Alert.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Alert.php";
require_once __ROOT__ . "/admin/Login.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Login.php";
if (!check_login()) { if (!check_login()) {
if (empty($_REQUEST)) { if (empty($_REQUEST)) {

@ -13,12 +13,12 @@ use mysqli;
use Question; use Question;
use QuestionQuery; use QuestionQuery;
require_once "../config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/head.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/head.php";
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
require_once __ROOT__ . "/Log.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
require_once __ROOT__ . "/admin/Alert.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Alert.php";
getMenu("题目管理"); getMenu("题目管理");

@ -1,11 +1,11 @@
<?php <?php
require_once "../config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/head.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/head.php";
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
require_once __ROOT__ . "/Log.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
require_once __ROOT__ . "/admin/Alert.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Alert.php";
getMenu("题目管理"); getMenu("题目管理");
@ -167,7 +167,7 @@ EOF;
<th scope="col">垃圾名</th> <th scope="col">垃圾名</th>
<th scope="col">垃圾分类</th> <th scope="col">垃圾分类</th>
<th scope="col">创建时间</th> <th scope="col">创建时间</th>
<th scope="col">修改时间</th> <!-- <th scope="col">修改时间</th>-->
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -184,7 +184,7 @@ EOF;
<th>$name</th> <th>$name</th>
<td>$category</td> <td>$category</td>
<td>$create_at</td> <td>$create_at</td>
<td>$update_at</td> <!-- <td>$update_at</td>-->
</tr> </tr>
EOF; EOF;
} }

@ -1,10 +1,10 @@
<?php <?php
require_once "../config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/baidu/BaiduAiRequest.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/baidu/BaiduAiRequest.php";
require_once __ROOT__ . "/entity/Garbage.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Garbage.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
require_once __ROOT__ . "/api/JsonResponse.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/api/JsonResponse.php";
//查询垃圾分类 //查询垃圾分类
function query_waste_soring($image_res) function query_waste_soring($image_res)

@ -1,9 +1,9 @@
<?php <?php
require_once "../config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/api/JsonResponse.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/api/JsonResponse.php";
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
//关键字查询 //关键字查询

@ -1,9 +1,9 @@
<?php <?php
require_once "../config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/api/JsonResponse.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/api/JsonResponse.php";
require_once __ROOT__ . "/Log.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
require_once __ROOT__ . "/database/Query.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/Query.php";
//题库题目数上限 //题库题目数上限
$max_count = 10; $max_count = 10;

@ -1,7 +1,7 @@
<?php <?php
require_once __ROOT__ . "/entity/ApiToken.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/ApiToken.php";
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
//api请求 //api请求

@ -9,8 +9,8 @@ define("db_config", array(
//默认日期格式 //默认日期格式
define("default_format", "Y-m-d H:i:s"); define("default_format", "Y-m-d H:i:s");
//根目录 //根目录
//define("__ROOT__", dirname(__FILE__)); //define("$_SERVER["DOCUMENT_ROOT"]", dirname(__FILE__));
//define("__ROOT__", "D:/JetBrains/PhpstormProjects/WasteSorting"); //define("$_SERVER["DOCUMENT_ROOT"]", "D:/JetBrains/PhpstormProjects/WasteSorting");
//define("__ROOT__", $_SERVER["DOCUMENT_ROOT"]); //define("$_SERVER["DOCUMENT_ROOT"]", $_SERVER["DOCUMENT_ROOT"]);

@ -1,7 +1,7 @@
<?php <?php
require_once __ROOT__ . "/config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/Log.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
interface DoExcute interface DoExcute
{ {

@ -1,11 +1,11 @@
<?php <?php
require_once __ROOT__ . "/entity/ApiToken.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/ApiToken.php";
require_once __ROOT__ . "/entity/Garbage.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Garbage.php";
require_once __ROOT__ . "/entity/Question.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Question.php";
require_once __ROOT__ . "/entity/Answer.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Answer.php";
require_once __ROOT__ . "/entity/Manager.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Manager.php";
require_once __ROOT__ . "/database/DbUtil.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
//Token查询 //Token查询
abstract class AbstractTokenQuery implements DoExcute abstract class AbstractTokenQuery implements DoExcute
{ {

@ -9,7 +9,7 @@ function getMenu($menu)
<script src="/static/js/popper.min.js"></script> <script src="/static/js/popper.min.js"></script>
<script src="/static/js/jquery-3.4.1.min.js"></script> <script src="/static/js/jquery-3.4.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/Cookie.js"></script>
</head> </head>
EOF; EOF;
} }

@ -1,11 +1,11 @@
<?php <?php
require_once "config.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/config.php";
require_once __ROOT__ . "/head.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/head.php";
getMenu("后台管理"); getMenu("后台管理");
require_once __ROOT__ . "/admin/Login.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/admin/Login.php";
if (!check_login()) { if (!check_login()) {
error_res("您尚未登陆,跳转到登陆页", "/admin/Manager.php"); error_res("您尚未登陆,跳转到登陆页", "/admin/Manager.php");
@ -13,7 +13,7 @@ if (!check_login()) {
} }
require_once __ROOT__ . "/entity/Menu.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Menu.php";
//菜单信息 //菜单信息
$menus = array("API" => new Menu("百度API配置", "/admin/ApiConfig.php"), new Menu("垃圾分类", "/admin/WasteSorting.php"), new Menu("题目管理", "/admin/Question.php")); $menus = array("API" => new Menu("百度API配置", "/admin/ApiConfig.php"), new Menu("垃圾分类", "/admin/WasteSorting.php"), new Menu("题目管理", "/admin/Question.php"));
@ -25,7 +25,9 @@ echo <<<EOF
<script> <script>
function logout() { function logout() {
if(confirm("确认退出?")){ if(confirm("确认退出?")){
delCookie("login_token");
delCookie("manager_name");
location.href="/admin/Manager.php"
} }
} }
</script> </script>

@ -0,0 +1,15 @@
function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if ((arr = document.cookie.match(reg)) !== null)
return unescape(arr[2]);
else
return null;
}

@ -1,9 +1,9 @@
<?php <?php
require_once "config.php"; //require_once $_SERVER["DOCUMENT_ROOT"] ."/config.php";
//require_once __ROOT__ . "/database/DbUtil.php"; //require_once $_SERVER["DOCUMENT_ROOT"] . "/database/DbUtil.php";
//require_once __ROOT__ . "/entity/Question.php"; //require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Question.php";
//require_once __ROOT__ . "/entity/Answer.php"; //require_once $_SERVER["DOCUMENT_ROOT"] . "/entity/Answer.php";
//require_once __ROOT__ . "/Log.php"; //require_once $_SERVER["DOCUMENT_ROOT"] . "/Log.php";
//echo <<<EOF //echo <<<EOF
//<html> //<html>
@ -24,5 +24,8 @@ require_once "config.php";
//EOF; //EOF;
//var_dump(array_search(new Answer(1, 2, 3, 4), array(new Answer(4, 5, 6, 7), new Answer(2, 2, 3, 4)))); //var_dump(array_search(new Answer(1, 2, 3, 4), array(new Answer(4, 5, 6, 7), new Answer(2, 2, 3, 4))));
var_dump(date_create(default_format)); $s1 = "dotcoo world!";
$s2 = "dotcoo";
$s3 = "hello dotcoo";
var_dump(substr($s1, -strlen($s2)) === $s2);

Loading…
Cancel
Save