140 lines
5.1 KiB
PHP
140 lines
5.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../app/lib/db.php';
|
|
require_once __DIR__ . '/../app/lib/auth.php';
|
|
require_once __DIR__ . '/../app/lib/helpers.php';
|
|
|
|
if (!empty($_SESSION['user_id'])) {
|
|
header('Location: /dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$pin = trim($_POST['pin'] ?? '');
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = trim($_POST['password'] ?? '');
|
|
$passwordConfirm = trim($_POST['password_confirm'] ?? '');
|
|
|
|
$requiredPin = getenv('FINANCIAL_REGISTER_PIN') ?: '0010';
|
|
|
|
if ($requiredPin === '' || !hash_equals($requiredPin, $pin)) {
|
|
throw new RuntimeException('PIN 코드가 올바르지 않습니다.');
|
|
}
|
|
|
|
if ($username === '' || $password === '') {
|
|
throw new RuntimeException('아이디와 비밀번호를 입력하세요.');
|
|
}
|
|
|
|
if (!preg_match('/^[a-zA-Z0-9_]{3,30}$/', $username)) {
|
|
throw new RuntimeException('아이디는 영문, 숫자, 밑줄 3~30자만 가능합니다.');
|
|
}
|
|
|
|
if (mb_strlen($password, 'UTF-8') < 4) {
|
|
throw new RuntimeException('비밀번호는 4자 이상 입력하세요.');
|
|
}
|
|
|
|
if ($password !== $passwordConfirm) {
|
|
throw new RuntimeException('비밀번호 확인이 일치하지 않습니다.');
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? LIMIT 1");
|
|
$stmt->execute([$username]);
|
|
|
|
if ($stmt->fetch()) {
|
|
throw new RuntimeException('이미 사용 중인 아이디입니다.');
|
|
}
|
|
|
|
$hash = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO users (username, password_hash, created_at)
|
|
VALUES (?, ?, NOW())
|
|
");
|
|
$stmt->execute([$username, $hash]);
|
|
|
|
$userId = (int)$pdo->lastInsertId();
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ? LIMIT 1");
|
|
$stmt->execute([$userId]);
|
|
$user = $stmt->fetch();
|
|
|
|
login_user($user, true);
|
|
|
|
header('Location: /dashboard.php');
|
|
exit;
|
|
} catch (Throwable $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>회원가입</title>
|
|
<meta name="theme-color" content="#0b2a66">
|
|
<meta name="mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-title" content="Financial">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
|
<link rel="icon" type="image/png" href="/favicon.png?v=2">
|
|
<link rel="apple-touch-icon" href="/favicon.png?v=2">
|
|
<link rel="manifest" href="/manifest.webmanifest">
|
|
<link href="/assets/vendor/bootstrap.min.css" rel="stylesheet">
|
|
<link href="/assets/app.css" rel="stylesheet">
|
|
<script src="https://chaegeon.com/log/bancheck.min.js?_=<?php echo time(); ?>"></script>
|
|
</head>
|
|
<body>
|
|
<div class="container py-5" style="max-width: 460px;">
|
|
<div class="card finance-card">
|
|
<div class="card-body p-4">
|
|
<h2 class="mb-4">회원가입</h2>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?= h($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" class="row g-3">
|
|
<div class="col-12">
|
|
<label class="form-label">가입 PIN 코드</label>
|
|
<input type="password" name="pin" class="form-control" inputmode="numeric" required>
|
|
<div class="form-text">관리자가 공유한 PIN 코드를 입력하세요.</div>
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<label class="form-label">아이디</label>
|
|
<input type="text" name="username" class="form-control" required autocomplete="username">
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<label class="form-label">비밀번호</label>
|
|
<input type="password" name="password" class="form-control" required autocomplete="new-password">
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<label class="form-label">비밀번호 확인</label>
|
|
<input type="password" name="password_confirm" class="form-control" required autocomplete="new-password">
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<button class="btn btn-primary w-100">가입하기</button>
|
|
</div>
|
|
|
|
<div class="col-12 text-center">
|
|
<a href="/login.php" class="text-decoration-none">이미 계정이 있습니다</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript" src="https://chaegeon.com/log/logger.js"></script>
|
|
<script src="/assets/pwa.js"></script>
|
|
</body>
|
|
</html>
|