文件
parlz-domain/reset_password.php

147 行
6.2 KiB
PHP

<?php
require_once 'functions.php';
$currentTheme = getTheme();
$message = null;
$success = false;
$token = $_GET['token'] ?? '';
// 验证token
if (empty($token)) {
$message = '缺少重置令牌';
$error = true;
} else {
// 验证token是否有效
$pdo = getDB();
$stmt = $pdo->prepare("SELECT id, email FROM users WHERE reset_token = ? AND reset_expires > NOW()");
$stmt->execute([$token]);
$user = $stmt->fetch();
if (!$user) {
$message = '重置链接无效或已过期,请重新申请';
$error = true;
} else {
$error = false;
}
}
// 处理密码重置
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error) {
$password = $_POST['password'] ?? '';
$confirm = $_POST['confirm_password'] ?? '';
if (strlen($password) < 6) {
$message = '密码长度至少6位';
} elseif ($password !== $confirm) {
$message = '两次密码输入不一致';
} else {
$result = resetPassword($token, $password);
if ($result['success']) {
$success = true;
$message = $result['message'];
} else {
$message = $result['message'];
}
}
}
$pageTitle = '重置密码 - ' . SITE_NAME;
$pageDescription = '重置您的 ' . SITE_NAME . ' 账号密码。';
?>
<!DOCTYPE html>
<html lang="zh-CN" data-theme="<?php echo $currentTheme; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($pageTitle); ?></title>
<meta name="description" content="<?php echo htmlspecialchars($pageDescription); ?>">
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?>/reset-password.php">
<meta name="robots" content="index, follow">
<link rel="alternate" hreflang="zh-CN" href="https://<?php echo $_SERVER['HTTP_HOST']; ?>/reset_password.php" />
<meta name="twitter:site" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/reset_password.php">
<meta property="og:title" content="<?php echo htmlspecialchars($pageTitle); ?>">
<meta property="og:description" content="<?php echo htmlspecialchars($pageDescription); ?>">
<meta property="og:image" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/favicon.ico">
<meta property="og:image:width" content="256">
<meta property="og:image:height" content="256">
<meta property="og:url" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/reset_password">
<meta property="og:type" content="website">
<meta property="og:site_name" content="<?php echo SITE_NAME; ?>">
<meta property="og:locale" content="zh_CN">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="<?php echo htmlspecialchars($pageTitle); ?>">
<meta name="twitter:description" content="<?php echo htmlspecialchars($pageDescription); ?>">
<meta name="twitter:image" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/favicon.ico">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebPage",
"name": "<?php echo htmlspecialchars($pageTitle); ?>",
"description": "<?php echo htmlspecialchars($pageDescription); ?>",
"url": "https://<?php echo $_SERVER['HTTP_HOST']; ?>/reset_password.php",
"inLanguage": "zh-CN"
}
</script>
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="auth-container">
<div class="auth-card">
<div class="icon-top">
<i class="fas fa-lock"></i>
</div>
<h2>重置密码</h2>
<p class="subtitle">设置新密码</p>
<?php if ($message && !$success): ?>
<div class="alert alert-error">
<i class="fas fa-exclamation-circle"></i>
<?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success-box">
<i class="fas fa-check-circle"></i>
<h3>✅ 密码重置成功</h3>
<p><?php echo htmlspecialchars($message); ?></p>
<a href="/login" class="btn btn-primary" style="display:inline-flex;width:auto;padding:12px 32px;">
<i class="fas fa-sign-in-alt"></i> 立即登录
</a>
</div>
<?php elseif ($error): ?>
<div class="alert alert-error" style="margin-top:10px;">
<i class="fas fa-exclamation-circle"></i>
<?php echo htmlspecialchars($message); ?>
</div>
<div class="auth-links" style="margin-top:20px;">
<a href="/forgot-password">重新申请重置链接</a>
</div>
<?php else: ?>
<form method="POST">
<div class="form-group">
<label><i class="fas fa-lock"></i> 新密码</label>
<input type="password" name="password" placeholder="至少6位" required minlength="6">
<div class="password-hint">密码至少6个字符</div>
</div>
<div class="form-group">
<label><i class="fas fa-lock"></i> 确认密码</label>
<input type="password" name="confirm_password" placeholder="再次输入新密码" required minlength="6">
</div>
<button type="submit" class="btn btn-primary">
<i class="fas fa-check"></i> 确认重置
</button>
</form>
<div class="auth-links">
<a href="/login">返回登录</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</body>
</html>