summaryrefslogtreecommitdiff
path: root/register.php
blob: 086a061088d5f547ab1d264d6798f50d4c47e4bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php session_start() ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Register an account - cflip.net forum</title>
<?php include_once 'includes/templates/head.php'; ?>
</head>
<body>
<?php include './includes/templates/header.php' ?>
	<h2>Register an account</h2>
	<form action="register.php" method="post">
		<label for="user_name">Username: </label><br>
		<input type="text" name="user_name" id="user_name"><br>
        <label for="invite_code">Invite Code: </label><br>
        <input type="text" name="invite_code" id="invite_code"><br>
		<label for="user_pass">Password: </label><br>
		<input type="password" name="user_pass"><br>
		<label for="user_pass_check">Re-enter password: </label><br>
		<input type="password" name="user_pass_check"><br>
		<input type="submit" name="submit">
	</form>
	<br>
<?php
include_once './includes/form/RegisterForm.php';
include_once './includes/model/User.php';
include_once './includes/error.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$form = new RegisterForm();
	$username = $form->validate_username($_POST['user_name']);
	$password = $form->validate_password($_POST['user_pass'], $_POST['user_pass_check']);
	$invite_code = $form->validate_invite_code($_POST['invite_code']);

    $form->on_success(function () use ($username, $password, $invite_code) {
        $inviter = new User();
        $inviter->get_by_invite_code($invite_code);
        $inviter->update_invite_code();

        $generation = $inviter->generation + 1;
        User::register($username, $password, $inviter);

        echo '<p class="success">Account successfully registered! You can now <a href="signin.php">sign in</a></p>';
    });
}
?>
</body>
</html>