-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
59 lines (51 loc) · 1.76 KB
/
signup.php
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
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
* Renders the page to signup up for an account and displays errors if failing to signup.
*/
require_once './vendor/autoload.php';
require 'session.php';
$loader = new Twig_Loader_Filesystem('./templates');
$twig = new Twig_Environment($loader, array());
session_start();
if(check_user($_SESSION['username']))
header('Location: welcome.php');
else
{
$user = $_POST['username'];
$pass = $_POST['pass'];
$pass_conf = $_POST['pass_confirmation'];
$email = $_POST['email'];
$errors = array();
if(isset($user, $pass, $pass_conf, $email))
{
$email_check = check_email($email);
if(empty($user))
$invalid_user = 'Please input an username.';
if(empty($pass))
$invalid_pass = 'Please input a password.';
if($pass !== $pass_conf)
$invalid_confirm = 'The two passwords do not match.';
if(check_user($user))
$invalid_user = 'The username has been taken.';
if(empty($email))
$invalid_email = 'Please input an email.';
elseif(!preg_match('/^[\S]+@[\S]+\.[\S]+$/', $email))
$invalid_email = 'That is not a valid email address.';
if(!empty($email_check))
$invalid_email = 'There is already an account associated to this email.';
if(!$invalid_email && !$invalid_user && !$invalid_pass && !$invalid_confirm)
{
add_verify($user, $pass, $email);
$success = 'You should recieve an email soon. Sometimes it may take about 30 minutes.';
}
}
echo $twig->render('signup.html', array('invalid_email' => $invalid_email,
'invalid_pass' => $invalid_pass,
'invalid_user' => $invalid_user,
'invalid_confirm' => $invalid_confirm,
'success' => $success,
'username' => $user,
'email' => $email,
'logged_in' => false));
}
?>