trying to port web app starter from PHP
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
$errors = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$res = User::AuthWithPassword($_POST['password'] ?? '');
|
||||
if ($res['result']) {
|
||||
header('Location: '.URL::link('account/profile'));
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = $res['message'];
|
||||
}
|
||||
}
|
||||
|
||||
?><!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login</h1>
|
||||
<?php if ($errors): ?>
|
||||
<div style="color: red"><?php echo htmlspecialchars(implode(', ', $errors)); ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="post">
|
||||
<label>Email: <input type="email" name="email" required></label><br>
|
||||
<label>Password: <input type="password" name="password" required></label><br>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
<p><a href="<?= URL::link('account/register') ?>">Register</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
User::Logout();
|
||||
header('Location: '.URL::link('account/login'));
|
||||
exit;
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
if (!User::IsSignedIn()) {
|
||||
header('Location: '.URL::link('account/login'));
|
||||
exit;
|
||||
}
|
||||
$u = User::$current_profile;
|
||||
?><!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Profile</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Profile</h1>
|
||||
<p>Email: <?php echo htmlspecialchars($u['email']); ?></p>
|
||||
<p>Roles: <?php echo htmlspecialchars(implode(', ', $u['roles'] ?? [])); ?></p>
|
||||
<p>Created: <?php echo htmlspecialchars(date('c', $u['created'] ?? time())); ?></p>
|
||||
<p><a href="<?= URL::link('account/logout') ?>">Logout</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
$errors = [];
|
||||
$success = false;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$res = User::Create(['email' => $email, 'password' => $password]);
|
||||
if ($res['result']) {
|
||||
$success = true;
|
||||
} else {
|
||||
$errors[] = $res['message'];
|
||||
}
|
||||
}
|
||||
|
||||
?><!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Register</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Register</h1>
|
||||
<?php if ($success): ?>
|
||||
<div style="color: green">Registration successful. <a href="<?= URL::link('account/login') ?>">Log in</a></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($errors): ?>
|
||||
<div style="color: red"><?php echo htmlspecialchars(implode(', ', $errors)); ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="post">
|
||||
<label>Email: <input type="email" name="email" required></label><br>
|
||||
<label>Password: <input type="password" name="password" required></label><br>
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user