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

require_once '../../includes/common.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'] ?? '';
    $password = $_POST['password'] ?? '';
    
    if (empty($username) || empty($password)) {
        json_error('账号或密码不能为空');
    }
    
    $stmt = $pdo->prepare("SELECT * FROM nxz_admin WHERE username = ?");
    $stmt->execute([$username]);
    $admin = $stmt->fetch();
    
    if ($admin && md5($password) === $admin['password']) {
        $_SESSION['admin_id'] = $admin['id'];
        $_SESSION['admin_user'] = $admin['username'];
        
        // 更新最后登录时间
        $update = $pdo->prepare("UPDATE nxz_admin SET last_login = ? WHERE id = ?");
        $update->execute([time(), $admin['id']]);
        
        json_success('登录成功');
    } else {
        json_error('账号或密码错误');
    }
}
?>