First git commit
This commit is contained in:
29
public_html/signup.php
Normal file
29
public_html/signup.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/lib/bootstrap.php';
|
||||
|
||||
$err = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_csrf();
|
||||
$n = trim((string)($_POST['username'] ?? ''));
|
||||
$p1 = (string)($_POST['pass'] ?? '');
|
||||
$p2 = (string)($_POST['pass2'] ?? '');
|
||||
if (!valid_username($n)) $err = 'Username: 3-16 letters, digits or underscore.';
|
||||
elseif (strlen($p1) < 4) $err = 'Password must be at least 4 characters.';
|
||||
elseif ($p1 !== $p2) $err = 'Passwords do not match.';
|
||||
elseif (username_taken($n)) $err = 'That username is taken.';
|
||||
else {
|
||||
$id = user_create($n, $p1);
|
||||
$_SESSION['uid'] = $id;
|
||||
redirect('/index.php');
|
||||
}
|
||||
}
|
||||
|
||||
page_start('Sign up', ['back' => '/index.php']);
|
||||
if ($err) p_err($err);
|
||||
p_form('/signup.php', [
|
||||
['name' => 'username', 'label' => 'Username', 'maxlength' => 16],
|
||||
['name' => 'pass', 'label' => 'Password', 'type' => 'password', 'maxlength' => 40],
|
||||
['name' => 'pass2', 'label' => 'Repeat', 'type' => 'password', 'maxlength' => 40],
|
||||
], 'Create');
|
||||
p_links([['/login.php', 'Already a member? Log in'], ['/index.php', 'Home']]);
|
||||
page_end();
|
||||
Reference in New Issue
Block a user