- initial
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once __DIR__.'/includes/boot.php';
|
||||
if (authed()) go('/index.php');
|
||||
if (setting('registration_enabled','1') !== '1') {
|
||||
flash('Registration is currently disabled.','warning'); go('/login.php');
|
||||
}
|
||||
$pageTitle = 'Create Account — Keyser WV';
|
||||
$errors = [];
|
||||
if (isPost()) {
|
||||
csrfCheck();
|
||||
$un = ps('username'); $em = ps('email'); $pw = ps('password'); $pw2 = ps('password2');
|
||||
if (strlen($un) < 3) $errors[] = 'Username must be at least 3 characters.';
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/',$un)) $errors[] = 'Username: letters, numbers, underscores only.';
|
||||
if ($em && !filter_var($em, FILTER_VALIDATE_EMAIL)) $errors[] = 'Invalid email address.';
|
||||
if (strlen($pw) < 6) $errors[] = 'Password must be at least 6 characters.';
|
||||
if ($pw !== $pw2) $errors[] = 'Passwords do not match.';
|
||||
if (!$errors && qval("SELECT id FROM users WHERE username=?",[$un])) $errors[] = 'Username already taken.';
|
||||
if (!$errors && $em && qval("SELECT id FROM users WHERE email=?",[$em])) $errors[] = 'Email already registered.';
|
||||
if (!$errors) {
|
||||
$id = qrun("INSERT INTO users(username,email,password)VALUES(?,?,?)",[$un,$em?:null,password_hash($pw,PASSWORD_BCRYPT)]);
|
||||
loginUser(qone("SELECT * FROM users WHERE id=?",[$id]));
|
||||
flash('Welcome to Discover Keyser WV!','success'); go('/index.php');
|
||||
}
|
||||
}
|
||||
include __DIR__.'/includes/header.php';
|
||||
?>
|
||||
<div class="form-box">
|
||||
<h1 class="form-title">Create Account</h1>
|
||||
<p class="form-sub">Join the Discover Keyser WV community</p>
|
||||
<?php if ($errors): ?><div class="err-box"><?=implode('<br>',array_map('e',$errors))?></div><?php endif; ?>
|
||||
<form method="POST">
|
||||
<?=csrfField()?>
|
||||
<div class="fg"><label class="flabel">USERNAME *</label><input type="text" name="username" class="finput" value="<?=e($_POST['username']??'')?>" autocomplete="username" required autofocus><div class="fhint">Letters, numbers, underscores. Minimum 3 characters.</div></div>
|
||||
<div class="fg"><label class="flabel">EMAIL (optional)</label><input type="email" name="email" class="finput" value="<?=e($_POST['email']??'')?>" autocomplete="email"></div>
|
||||
<div class="fg"><label class="flabel">PASSWORD *</label><input type="password" name="password" class="finput" autocomplete="new-password" required><div class="fhint">Minimum 6 characters.</div></div>
|
||||
<div class="fg"><label class="flabel">CONFIRM PASSWORD *</label><input type="password" name="password2" class="finput" autocomplete="new-password" required></div>
|
||||
<button type="submit" class="btn btn-primary btn-block" style="margin-top:.5rem">Create Account</button>
|
||||
</form>
|
||||
<p style="text-align:center;margin-top:1.25rem;font-size:.88rem;color:var(--text-m)">Already have an account? <a href="/login.php">Sign in</a></p>
|
||||
</div>
|
||||
<?php include __DIR__.'/includes/footer.php'; ?>
|
||||
Reference in New Issue
Block a user