-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateNewAccount.php
More file actions
207 lines (184 loc) · 7.1 KB
/
createNewAccount.php
File metadata and controls
207 lines (184 loc) · 7.1 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
require_once("C:\\xampp\\htdocs\\BusinessDatabase\\Includes\\dp.php");
require_once ("C:\\xampp\\php\\pear\\Mail.php");
/** other variables */
$businessNameIsUnique = true;
$userNameIsUnique = true;
$UserAccountEmailIsUnique = true;
$BusinessAccountEmailIsUnique = true;
$passwordIsValid = true;
$userIsEmpty = false;
$accountEmailIsValid = true;
$accountEmailIsEmpty = false;
$passwordIsEmpty = false;
$password2IsEmpty = false;
/** Check that the page was requested from itself via the POST method. */
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["user"]=="") {
$userIsEmpty = true;
}
if ($_POST["accountEmail"]=="") {
$accountEmailIsEmpty = true;
}
session_start();
$_SESSION['user'] = $_POST['user'];
$userID = BusinessDB::getInstance()->get_user_id_by_name($_POST["user"]);
$userIDnum=mysqli_num_rows($userID);
if ($userIDnum) {
$userNameIsUnique = false;
}
$UserAccountEmailID = BusinessDB::getInstance()->get_user_accountEmail_id_by_name($_POST["accountEmail"]);
$UserAccountEmailIDnum=mysqli_num_rows($UserAccountEmailID);
if ($UserAccountEmailIDnum) {
$UserAccountEmailIsUnique = false;
}
$BusinessAccountEmailID = BusinessDB::getInstance()->get_business_accountEmail_id_by_name($_POST["accountEmail"]);
$BusinessAccountEmailIDnum=mysqli_num_rows($BusinessAccountEmailID);
if ($BusinessAccountEmailIDnum) {
$BusinessAccountEmailIsUnique = false;
}
$businessID = BusinessDB::getInstance()->get_business_id_by_name_only($_POST["user"]);
$businessIDnum=mysqli_num_rows($businessID);
if ($businessIDnum) {
$businessNameIsUnique = false;
}
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['accountEmail'])){
$accountEmailIsValid = false;
} else {
$email = $_POST["accountEmail"];
}
if ($_POST["password"]=="") {
$passwordIsEmpty = true;
}
if ($_POST["password2"]=="") {
$password2IsEmpty = true;
}
if ($_POST["password"]!=$_POST["password2"]) {
$passwordIsValid = false;
}
/** Check whether the boolean values show that the input data was validated successfully.
* If the data was validated successfully, add it as a new entry in the "wishers" database.
* After adding the new entry, close the connection and redirect the application to editWishList.php.
*/
if (!$userIsEmpty && $userNameIsUnique && $accountEmailIsValid && $businessNameIsUnique && $BusinessAccountEmailIsUnique && $UserAccountEmailIsUnique && !$passwordIsEmpty && !$password2IsEmpty && $passwordIsValid) {
$hash = md5(rand(0,1000));
if (isset($_POST['isBusiness'])) {
BusinessDB::getInstance()->create_business($_POST["user"], $email, $_POST["password"], $hash);
$link = "verifyBusiness.php?email=";
echo $link;
} else if (!isset($_POST['isBusiness'])) {
echo $email;
BusinessDB::getInstance()->create_user($_POST["user"], $email, $_POST["password"], $hash);
$link = "verifyUser.php?email=";
echo $link;
}
echo $email;
$from = "Earthbird <earthbird@example.com>";
$to = $email;
$subject = "Earthbird Verification";
$body = '
Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
------------------------
Username: '.$_POST['user'].'
Password: '.$_POST['password'].'
------------------------
Please click this link to activate your account:
http://localhost/BusinessDatabase/' . $link . $email.'&hash='.$hash.'
'; // Our message above including the link
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "chrisssaring@gmail.com";
$password = "chrisrocks2468";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
}
?>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css?<?php echo time(); ?>" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<span href="#" class="button" id="toggle-login">Register</span>
<div id="login">
<div id="triangle"></div>
<h1>Register</h1>
<form action="createNewAccount.php" method="POST">
<input type="text" placeholder="Username" name="user" /><br>
<p class="error">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!$businessNameIsUnique || !$userNameIsUnique) {
echo "That account name is taken.";
}
if ($userIsEmpty) {
echo "Please enter a usename.";
}
}
?>
</p>
<input type="email" placeholder="Email" name="accountEmail" /><br>
<p class="error">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!$UserAccountEmailIsUnique || !$BusinessAccountEmailIsUnique) {
echo "That email account is already in use.";
}
if ($accountEmailIsEmpty) {
echo "Please enter an email.";
}
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['accountEmail'])){
echo "Please enter a valid email.";
}
}
?>
</p>
<input type="password" placeholder="Password" name="password" /><br>
<p class="error">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($passwordIsEmpty) {
echo "Please enter a password.";
}
}
?>
</p>
<input type="password" placeholder="Confirm Password" name="password2" /><br>
<p class="error">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($password2IsEmpty) {
echo "Please confirm your password.";
}
}
?>
</p>
<input type="submit" value="Register" /> <br><br>
Are you registering as a business? <input type="checkbox" name="isBusiness"/>
</form>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>