文件
parlz-domain/auth.php
T

150 行
7.5 KiB
PHP

<?php
require_once 'functions.php';
$action = $_GET['action'] ?? 'login';
$message = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? 'login';
if ($action === 'register') {
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = $_POST['password'];
$confirmPassword = $_POST['confirm_password'];
$inviteCode = trim($_POST['invite_code'] ?? '');
if ($password !== $confirmPassword) {
$message = ['success' => false, 'message' => '两次密码输入不一致。'];
} elseif (strlen($password) < 6) {
$message = ['success' => false, 'message' => '密码长度至少 6 位。'];
} else {
$message = registerUser($username, $email, $password, $inviteCode);
}
} elseif ($action === 'login') {
$username = trim($_POST['username']);
$password = $_POST['password'];
$message = loginUser($username, $password);
if ($message['success']) {
header('Location: dashboard.php');
exit;
}
}
}
$currentTheme = getTheme();
?>
<!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 $action === 'login' ? '登录' : '注册'; ?> - <?php echo SITE_NAME; ?></title>
<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">
<meta name="description" content="登录,Parlz Domains 账号,管理你的二级域名。">
<meta name="keywords" content="登录,用户登录,域名管理">
<link rel="icon" href="favicon.ico">
<meta name="robots" content="index, follow">
<link rel="alternate" hreflang="zh-CN" href="https://<?php echo $_SERVER['HTTP_HOST']; ?>/auth.php" />
<link rel="me" href="https://git.parlz.com/Xiaoxiaobai5724/parlz-domain">
<meta property="og:title" content="登录 - Parlz Domains">
<meta property="og:description" content="登录 Parlz Domains 账号,管理你的二级域名。">
<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']; ?>/auth.php">
<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 SITE_NAME; ?>">
<meta name="twitter:description" content="登录 <?php echo SITE_NAME; ?> 账号。">
<meta name="twitter:image" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/favicon.ico">
<meta name="twitter:site" content="https://<?php echo $_SERVER['HTTP_HOST']; ?>/auth.php">
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?>/auth.php">
</head>
<body>
<div class="container auth-container">
<div class="auth-card">
<h2><i class="fas fa-<?php echo $action === 'login' ? 'sign-in-alt' : 'user-plus'; ?>"></i>
<?php echo $action === 'login' ? '登录' : '注册'; ?>
</h2>
<?php if ($message): ?>
<div class="alert alert-<?php echo $message['success'] ? 'success' : 'error'; ?>">
<i class="fas <?php echo $message['success'] ? 'fa-check-circle' : 'fa-exclamation-circle'; ?>"></i>
<?php echo htmlspecialchars($message['message']); ?>
</div>
<?php endif; ?>
<?php if ($action === 'login'): ?>
<form method="POST">
<input type="hidden" name="action" value="login">
<div class="form-group">
<label><i class="fas fa-user"></i> 账号</label>
<input type="text" name="username" placeholder="请输入用户名或邮箱..." required>
</div>
<div class="form-group">
<label><i class="fas fa-lock"></i> 密码</label>
<input type="password" name="password" placeholder="请输入密码..." required>
</div>
<button type="submit" class="btn btn-primary" style="width:100%;justify-content:center;">
<i class="fas fa-sign-in-alt"></i> 登录
</button>
</form>
<div class="auth-switch">
还没有账号?<a href="?action=register">立即注册</a>
<a href="forgot_password.php">忘记密码?</a>
注册用户默认已同意 <a href="/doc/?file=md/使用协议.md">使用协议</a> 和 <a href="/doc/?file=md/隐私政策.md">隐私政策</a>。
</div>
<?php else: ?>
<form method="POST">
<input type="hidden" name="action" value="register">
<div class="form-group">
<label><i class="fas fa-user"></i> 用户名</label>
<input type="text" name="username" placeholder="请输入用户名..." required minlength="3" maxlength="30">
</div>
<div class="form-group">
<label><i class="fas fa-envelope"></i> 邮箱</label>
<input type="email" name="email" placeholder="请输入邮箱地址..." required>
</div>
<div class="form-group">
<label><i class="fas fa-lock"></i> 密码</label>
<input type="password" name="password" placeholder="请输入至少 6 位数的密码..." required minlength="6">
</div>
<div class="form-group">
<label><i class="fas fa-lock"></i> 确认密码</label>
<input type="password" name="confirm_password" placeholder="请再次输入密码" required minlength="6">
</div>
<div class="form-group">
<label><i class="fas fa-gift"></i> 邀请码(选填)</label>
<input type="text" name="invite_code" placeholder="输入邀请码可获得额外积分...">
<div class="invite-hint"><i class="fas fa-info-circle"></i> 使用邀请码注册可让邀请人获得 <?php echo INVITE_CREDIT; ?> 积分</div>
</div>
<button type="submit" class="btn btn-primary" style="width:100%;justify-content:center;">
<i class="fas fa-user-plus"></i> 注册
</button>
</form>
<div class="auth-switch">
已有账号?<a href="?action=login">立即登录</a>
<a href="forgot_password.php">忘记密码?</a>
注册用户默认已同意 <a href="/doc/?file=md/使用协议.md">使用协议</a> 和 <a href="/doc/?file=md/隐私政策.md">隐私政策</a>。
</div>
<?php endif; ?>
</div>
</div>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebPage",
"name": "登录 - <?php echo SITE_NAME; ?>",
"description": "登录 <?php echo SITE_NAME; ?> 账号,管理你的二级域名。",
"url": "https://<?php echo $_SERVER['HTTP_HOST']; ?>/login",
"inLanguage": "zh-CN"
}
</script>
</body>
</html>