<?php 
  include '../core/core.php';
  if($act=='login'){
    $act = daddslashes($_GET['act'])??null;
    $name = daddslashes($_POST['name'])??null;
    $password = daddslashes($_POST['password'])??null;
    
    if($name==conf('name') && $password==conf('password')){
      $adminToken = md5($name.$password);
      setcookie("adminToken", $adminToken, time() + 604800, '/');
      exit('{"code":1,"msg":"登陆成功"}');
    }else{
      exit('{"code":0,"msg":"账号或密码错误"}');
    }
    exit();
  }
  if($_COOKIE['adminToken']==md5(conf('name').conf('password'))){
   exit('<script>alert("您已经登陆");window.location.href="./index.php"</script>');
  }
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>雨尘SEO静态页面生成系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../public/static/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../public/static/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="../public/static/layuiadmin/style/login.css" media="all">
  <script src="../public/static/jquery-3.5.1.min.js"></script>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>后台管理系统</h2>
        <p>雨尘SEO静态页面生成系统</p>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" name="name" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
        </div>
      </div>
    </div>
    
    <div class="layui-trans layadmin-user-login-footer">
        <span><a href="http://wpa.qq.com/msgrd?v=3&uin=1900432277&site=qq&menu=yes" target="_blank">联系作者</a></span>
      </p>
    </div>
  </div>

<script src="../public/static/layuiadmin/layui/layui.all.js"></script>
  <script>
  layui.config({
      base: '../public/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index','form','table'], function(){
      var $ = layui.$
      ,table = layui.table
      ,layedit = layui.layedit
      ,laydate = layui.laydate
      ,form = layui.form
      ,admin = layui.admin
      ,element = layui.element
      ,layer = layui.layer;
      element.render();

       form.on('submit(login)', function(data){
          name = data.field.name;
          password = data.field.password;
          var load = layer.load({time:false});
          $.ajax({
                url: "./login.php?act=login",
                data: {name,password},
                type: "POST",
                dataType: "json",
                success: function(data){
                    layer.close(load);
                      if(data.code==1){
                        layer.msg(data.msg,{icon:6});
                        window.location.href="./index.php";
                      }else{
                        layer.msg(data.msg,{icon:5});
                      }
                },
                error: function(data){
                    layer.close(load);
                    layer.msg("未知错误");
                }
            });
        });
  });
  </script>
<?php 
  include 'foot.php';
?>