<?php
/**
 * Name: Nxz官网系统
 * URI: https://www.nxzlm.com/
 * Description: 逆行者官网系统源码，简单好用带后台
 * Version: 1.0.0
 * Author: 逆行者联盟
 */
require_once '../includes/common.php';

if (isset($_SESSION['admin_id'])) {
    header("Location: index.php");
    exit;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>后台登录 - <?php echo htmlspecialchars(get_config('site_name')); ?></title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css">
    <style>
        body { background-color: #f2f2f2; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
        .login-box { width: 400px; padding: 30px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
        .login-header { text-align: center; margin-bottom: 30px; }
        .login-header h2 { font-weight: 300; color: #333; margin-bottom: 10px; }
        .login-header p { color: #999; font-size: 14px; }
        .login-copyright { text-align: center; color: #ccc; margin-top: 30px; font-size: 12px; }
    </style>
</head>
<body>

<div class="login-box">
    <div class="login-header">
        <h2>系统管理后台</h2>
        <p><?php echo htmlspecialchars(get_config('site_name')); ?></p>
    </div>
    
    <form class="layui-form" id="loginForm">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input type="text" name="username" lay-verify="required" placeholder="管理员账号" lay-reqtext="请填写管理员账号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="password" lay-verify="required" placeholder="密码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 30px;">
            <button class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit lay-filter="login">登 录</button>
        </div>
    </form>
    
    <div class="login-copyright">
        © <?php echo date('Y'); ?> <?php echo $nxz_copyright['Name']; ?> (<?php echo $nxz_copyright['Author']; ?>)
    </div>
</div>

<script src="../assets/layui/layui.js"></script>
<script>
layui.use(['form', 'layer', 'jquery'], function(){
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;
    
    form.on('submit(login)', function(data){
        var loadIndex = layer.load(2);
        $.post('api/login.php', data.field, function(res){
            layer.close(loadIndex);
            if(res.code === 0){
                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                    location.href = 'index.php';
                });
            } else {
                layer.msg(res.msg, {icon: 2, anim: 6});
            }
        }, 'json').fail(function() {
            layer.close(loadIndex);
            layer.msg('请求接口失败，请检查网络或服务端错误。', {icon: 2, anim: 6});
        });
        return false;
    });
});
</script>
</body>
</html>