ユーザーの申し込み

This commit is contained in:
2025-12-08 00:56:06 +09:00
parent f6389eedc9
commit c7537ab36f
7 changed files with 306 additions and 43 deletions

View File

@@ -44,7 +44,7 @@ class User {
$description = 'サイトにサインイン';
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'about');
$tmpl->assign('curPage', 'auth');
$tmpl->assign('custCss', false);
$tmpl->assign('menu', $this->getMenu());
$tmpl->assign('description', $description);
@@ -58,7 +58,7 @@ class User {
public function logout(array $params): void {
try {
$auth = new Auth();
$auth = new Auth;
$user = $auth->getLoggedInUser();
if (!$user) {
header('Location: /');
@@ -72,4 +72,62 @@ class User {
throw new \Exception($e->getMessage());
}
}
public function register(array $params): void {
if (!AUTH_REGISTER_ENABLED) return;
try {
$auth = new Auth;
$user = $auth->getLoggedInUser();
if ($user) {
header('Location: /');
exit();
}
$doRegister = $_SERVER['REQUEST_METHOD'] === 'POST';
$error = '';
$nyuU = '';
$nyuE = '';
if ($doRegister) {
$a = [];
if (count($_POST) === 4) {
$i = 0;
foreach ($_POST as $p) {
$a[(int)$i] = $p;
$i++;
}
}
$auth = new Auth;
$res = $auth->mkUser($a[0], $a[1], $a[2], $a[3]);
if (!$res->isSuccess) {
$error = $res->message;
$nyuU = $a[0];
$nyuE = $a[3];
} else {
$auth = new Auth($a[0]);
$auth->setToken($a[0], $a[1]);
header('Location: /');
exit();
}
}
$tmpl = new Template('/');
$pagetit = '登録';
$description = 'サイトに登録';
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'auth');
$tmpl->assign('custCss', false);
$tmpl->assign('menu', $this->getMenu());
$tmpl->assign('description', $description);
$tmpl->assign('error', $error);
$tmpl->assign('nyuU', $nyuU);
$tmpl->assign('nyuE', $nyuE);
$tmpl->render('register');
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
}