-
Notifications
You must be signed in to change notification settings - Fork 4
/
_makeAccount.php
141 lines (121 loc) · 4.67 KB
/
_makeAccount.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/*
Copyright 2020 FWBer.com
This file is part of FWBer.
FWBer is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FWBer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero Public License for more details.
You should have received a copy of the GNU Affero Public License
along with FWBer. If not, see <https://www.gnu.org/licenses/>.
*/
include("_init.php");
include("_secrets.php");
include("_names.php");
include("_debug.php");
if($_SERVER["REQUEST_METHOD"] != "POST") {header("Location: ".getSiteURL()."/join");exit();}
if(
(
isset($_POST['nameEmail']) &&!empty($_POST['nameEmail'])
&&isset($_POST['namePassword']) &&!empty($_POST['namePassword'])
&&isset($_POST['nameVerify']) &&!empty($_POST['nameVerify'])
&&isset($_POST['nameAgreeLegalAge']) &&!empty($_POST['nameAgreeLegalAge'])
&&isset($_POST['nameAgreeTOS']) &&!empty($_POST['nameAgreeTOS'])
)==false
)
{
header("Location: ".getSiteURL()."/join");
exit();
}
$db = mysqli_connect($dburl,$dbuser,$dbpass);
if(!$db)exit(mysqli_connect_error());
//escape the values
$email = mysqli_real_escape_string($db,$_POST['nameEmail']);
$password = mysqli_real_escape_string($db,$_POST['namePassword']);
$verify = mysqli_real_escape_string($db,$_POST['nameVerify']);
if(
strlen($password)<5 ||
strcmp($password,$verify)!=0 ||
$_POST['nameAgreeLegalAge']!=true ||
$_POST['nameAgreeTOS']!=true ||
!filter_var($email,FILTER_VALIDATE_EMAIL)
)
{
header("Location: ".getSiteURL()."/join");
exit();
}
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha)
{
header("Location: ".getSiteURL()."/join");
exit();
}
$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($reCaptchaSecretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
if($responseKeys["success"]==false)
{
header("Location: ".getSiteURL()."/join");
exit();
}
//connect to the database to see if the email is already registered.
$dbquerystring = sprintf("SELECT email, verifyHash FROM ".$dbname.".users WHERE email='%s'",$email);
$dbquery = mysqli_query($db, $dbquerystring);
$dbresult = mysqli_fetch_array($dbquery);
mysqli_free_result($dbquery);
$emailExists = true;
if($dbresult==null || $dbresult['email']==null || $dbresult['email']!=$email)
{
$emailExists=false;
}
?>
<!doctype html>
<html lang="en">
<head>
<title><?php require_once("_names.php"); echo getSiteName(); ?> - New Account Confirmation<?php require_once("_names.php"); echo getTitleTagline(); ?></title>
<?php include("head.php");?>
</head>
<body class="d-flex flex-column h-100">
<?php include("h.php");?>
<div class="col-sm-12 my-auto text-center">
<div style="color:#0096ff;font-size:14pt;text-shadow:#aad 1px 1px 1px;">
Your account has been created.<br><br>
<div style="color:#000;font-size:12pt;text-shadow:#aaa 1px 1px 1px;">
Please check your email for a verification link.<br>
If it is in the spam folder please mark it as not spam.<br>
<br><br>
</div>
</div>
<?php
if($emailExists==false)
{
$dateJoined = time();
$verifyHash = md5(rand(0,1000));
$dbquerystring = "INSERT INTO ".$dbname.".users (email, passwordHash, verifyHash, dateJoined) VALUES(
'". mysqli_real_escape_string($db,$email) ."',
'". mysqli_real_escape_string($db,getSaltedPassword($password,$dateJoined)) ."',
'". mysqli_real_escape_string($db,$verifyHash) ."',
'". mysqli_real_escape_string($db,$dateJoined) ."') ";
$dbquery = mysqli_query($db, $dbquerystring);
}
else
{
$verifyHash = $dbresult['verifyHash'];
}
mysqli_close($db);
include("_emailFunctions.php");
sendJoinVerificationEmail($email,$verifyHash,$emailExists);
?>
</div>
<?php include("f.php");?>
</body>
</html>