|
1
|
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/config.inc.php"); ?> |
|
2
|
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/db_helper.php"); ?> |
|
3
|
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/time_manip.php"); ?> |
|
4
|
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/user_helper.php"); ?> |
|
5
|
|
|
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/video_helper.php"); ?> |
|
6
|
|
|
<?php $__video_h = new video_helper($__db); ?> |
|
7
|
|
|
<?php $__user_h = new user_helper($__db); ?> |
|
8
|
|
|
<?php $__db_h = new db_helper(); ?> |
|
9
|
|
|
<?php $__time_h = new time_helper(); ?> |
|
10
|
|
|
<?php |
|
11
|
|
|
function remove_emoji($text) { |
|
12
|
|
|
|
|
13
|
|
|
$clean_text = ""; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
// Match Emoticons |
|
16
|
|
|
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u'; |
|
17
|
|
|
$clean_text = preg_replace($regexEmoticons, '', $text); |
|
18
|
|
|
|
|
19
|
|
|
// Match Miscellaneous Symbols and Pictographs |
|
20
|
|
|
$regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u'; |
|
21
|
|
|
$clean_text = preg_replace($regexSymbols, '', $clean_text); |
|
22
|
|
|
|
|
23
|
|
|
// Match Transport And Map Symbols |
|
24
|
|
|
$regexTransport = '/[\x{1F680}-\x{1F6FF}]/u'; |
|
25
|
|
|
$clean_text = preg_replace($regexTransport, '', $clean_text); |
|
26
|
|
|
|
|
27
|
|
|
// Match Miscellaneous Symbols |
|
28
|
|
|
$regexMisc = '/[\x{2600}-\x{26FF}]/u'; |
|
29
|
|
|
$clean_text = preg_replace($regexMisc, '', $clean_text); |
|
30
|
|
|
|
|
31
|
|
|
// Match Dingbats |
|
32
|
|
|
$regexDingbats = '/[\x{2700}-\x{27BF}]/u'; |
|
33
|
|
|
$clean_text = preg_replace($regexDingbats, '', $clean_text); |
|
34
|
|
|
|
|
35
|
|
|
return $clean_text; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['password'] && $_POST['username']) { |
|
40
|
|
|
$request = (object) [ |
|
41
|
|
|
"username" => $_POST['username'], |
|
42
|
|
|
"password" => $_POST['password'], |
|
43
|
|
|
"email" => $_POST['email'], |
|
44
|
|
|
"password_hash" => password_hash($_POST['password'], PASSWORD_DEFAULT), |
|
45
|
|
|
|
|
46
|
|
|
"error" => (object) [ |
|
47
|
|
|
"message" => "", |
|
48
|
|
|
"status" => "OK" |
|
49
|
|
|
] |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
$request->username = remove_emoji($request->username); |
|
53
|
|
|
|
|
54
|
|
|
if (!filter_var($request->email, FILTER_VALIDATE_EMAIL)) |
|
55
|
|
|
{ $request->error->message = "Your email is invalid!"; $request->error->status = ""; } |
|
56
|
|
|
if(strlen($request->username) > 21) |
|
57
|
|
|
{ $request->error->message = "Your username must be shorter than 20 characters."; $request->error->status = ""; } |
|
58
|
|
|
if(strlen($request->password) < 8) |
|
59
|
|
|
{ $request->error->message = "Your password must at least be 8 characters long."; $request->error->status = ""; } |
|
60
|
|
|
if(!preg_match('/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/', $request->password)) |
|
61
|
|
|
{ $request->error->message = "Include numbers and letters in your password!"; $request->error->status = ""; } |
|
62
|
|
|
if(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $request->username)) |
|
63
|
|
|
{ $request->error->message = "Your username cannot contain any special characters!"; $request->error->status = ""; } |
|
64
|
|
|
if(!preg_match('/^\S+\w\S{1,}/', $request->username)) |
|
65
|
|
|
{ $request->error->message = "Your username cannot contain any special characters!"; $request->error->status = ""; } |
|
66
|
|
|
if(empty(trim($request->username))) |
|
67
|
|
|
{ $request->error->message = "Your username cannot be empty!"; $request->error->status = ""; } |
|
68
|
|
|
|
|
69
|
|
|
$stmt = $__db->prepare("SELECT username FROM users WHERE username = lower(:username)"); |
|
70
|
|
|
$stmt->bindParam(":username", $request->username); |
|
71
|
|
|
$stmt->execute(); |
|
72
|
|
|
if($stmt->rowCount()) |
|
73
|
|
|
{ $request->error->message = "There's already a user with that same username!"; $request->error->status = ""; } |
|
74
|
|
|
|
|
75
|
|
|
if($request->error->status == "OK") { |
|
76
|
|
|
$stmt = $__db->prepare("INSERT INTO users (username, email, password) VALUES (:username, :email, :password)"); |
|
77
|
|
|
$stmt->bindParam(":username", $request->username); |
|
78
|
|
|
$stmt->bindParam(":email", $request->email); |
|
79
|
|
|
$stmt->bindParam(":password", $request->password_hash); |
|
80
|
|
|
$stmt->execute(); |
|
81
|
|
|
|
|
82
|
|
|
$_SESSION['siteusername'] = $request->username; |
|
83
|
|
|
header("Location: /"); |
|
84
|
|
|
} else { |
|
85
|
|
|
$_SESSION['error'] = $request->error; |
|
86
|
|
|
header("Location: /sign_up"); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
?> |
|
|
|
|
|