-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
281 lines (255 loc) · 11.8 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
include './config/conn.php';
// Start Session
session_start();
if(!empty($_SESSION['name'])) {
if(isset($_SESSION['email'])) {
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$status = $_SESSION['status'];
if($email != "" && $status == "logged in")
{
header("Location: feed.php");
exit();
}
}
}
// check Register request
if (!empty($_POST['btnRegister'])) {
if ($_POST['name'] == "") {
$register_error_message = 'Name field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['fname'] == "") {
$register_error_message = 'first name field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['lname'] == "") {
$register_error_message = 'last name field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['email'] == "") {
$register_error_message = 'Email field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['password'] == "") {
$register_error_message = 'Password field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['repeat_password'] == "") {
$register_error_message = 'Repeat Password field is required!';
echo $register_error_message . "<br>";
} else if ($_POST['repeat_password'] != $_POST['password']) {
$register_error_message = 'Passwords don\'t match!';
echo $register_error_message . "<br>";
} else if (strlen($_POST['repeat_password']) < 6) {
$register_error_message = 'Password must be at least 6 characters!';
echo $register_error_message . "<br>";
} else if (!preg_match('/[^a-zA-Z]+/',($_POST['repeat_password']))) {
$register_error_message = 'Passwords must have at least one special character!';
echo $register_error_message . "<br>";
} else {
try {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$fullname = $fname . " " . $lname;
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$rating = 0;
$imagecount = 0;
$password = $_POST['password'];
$enc_password = hash('sha256', $password);
$confirm_code=md5(uniqid(rand()));
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO users(fullname, name, email, gender, rating, imagecount, password, confirmation_code)
VALUES(:fullname, :name, :email, :gender, :rating, :imagecount, :password, :confirmation_code)");
$stmt->bindParam(':fullname', $fullname);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':gender', $gender);
$stmt->bindParam(':rating', $rating);
$stmt->bindParam(':imagecount', $imagecount);
$stmt->bindParam(':password', $enc_password);
$stmt->bindParam(':confirmation_code', $confirm_code);
$target_dir = "./images/user_images/";
$image_name = "temp-profile.png";
$image_type = "profile";
$target_file = $target_dir . $image_name;
$stmt_uploadprofilepic = $conn->prepare("INSERT INTO images(image_name, image_type, image_creator, image_creator_email, image_url)
VALUES(:image_name, :image_type, :image_creator, :image_creator_email, :image_url)");
$stmt_uploadprofilepic->bindParam(':image_name', $image_name);
$stmt_uploadprofilepic->bindParam(':image_type', $image_type);
$stmt_uploadprofilepic->bindParam(':image_creator', $name);
$stmt_uploadprofilepic->bindParam(':image_creator_email', $email);
$stmt_uploadprofilepic->bindParam(':image_url', $target_file);
$stmt0 = $conn->prepare("SELECT id FROM users WHERE name=:name");
$stmt0->bindParam(':name', $name);
$stmt0->execute();
$stmt1 = $conn->prepare("SELECT id FROM users WHERE email=:email");
$stmt1->bindParam(':email', $email);
$stmt1->execute();
if (($stmt0->rowCount() > 0) || ($stmt1->rowCount() > 0)) {
if ($stmt0->rowCount() > 0) {
echo "Email Is Already In Use! <br>";
}else{
echo "Username Is Already In Use! <br>";
}
} else{
//echo $gender . "</br>";
//echo "Account Created Login To Continue! <br>";
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your Matcha signup confirmation link here";
// From
$header="from: Matcha";
// Your message
$message="Your Confirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://127.0.0.1:8080/matcha/inc/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
// if your email succesfully sent
if($sentmail){
$stmt->execute();
$stmt_uploadprofilepic->execute();
/*$matchestable = $name . "§matches";
echo $matchestable . "<br>";
$sql_creatematches = "CREATE TABLE IF NOT EXISTS "
. $matchestable
. " ("
. "match_id int NOT NULL AUTO_INCREMENT,"
. "match_message_id varchar(100),"
. "match_name varchar(100),"
. "match_creator varchar(50),"
. "match_creator_email varchar(50),"
. "match_timestamp timestamp NOT NULL DEFAULT current_timestamp on update current_timestamp,"
. "PRIMARY KEY (match_id));";
try {
$conn->exec($sql_creatematches);
} catch (PDOException $e) {
echo "error: " . $sql_creatematches . "<br>" . $e->getMessage();
}*/
echo "Your Confirmation link Has Been Sent To Your Email Address.";
} else {
echo "Cannot send Confirmation link to your e-mail address";
}
}
} catch (PDOException $e) {
echo "error: " . $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Matcha</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./assets/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="./assets/css/animate.css">
<link rel="stylesheet" type="text/css" href="./assets/css/font.css">
<link rel="stylesheet" type="text/css" href="./assets/css/li-scroller.css">
<link rel="stylesheet" type="text/css" href="./assets/css/slick.css">
<link rel="stylesheet" type="text/css" href="./assets/css/jquery.fancybox.css">
<link rel="stylesheet" type="text/css" href="./assets/css/theme.css">
<link rel="stylesheet" type="text/css" href="./assets/css/style.css">
<!--[if lt IE 9]>
<script src="../assets/js/html5shiv.min.js"></script>
<script src="../assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="preloader">
<div id="status"> </div>
</div>
<a class="scrollToTop" href="#"><i class="fa fa-angle-up"></i></a>
<div class="container">
<header id="header">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="header_top">
<div class="header_top_left">
<ul class="top_nav">
<li><a href="./index.php">Home</a></li>
</ul>
</div>
<div class="header_top_right">
<a href="./inc/logout.php"><p>Logout</p></a>
</div>
</div>
</div>
</div>
</header>
<section id="contentSection">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<div class="left_content">
<div class="contact_area">
<h2>Sign Up</h2>
<p>Fill in the form below and sign up!</p>
<form action="signup.php" method="post">
<div class="form-group">
<label for="">Username</label>
<input type="text" name="name" class="form-control" placeholder="JohnDoer"/>
</div>
<div class="form-group">
<label for="">First Name</label>
<input type="text" name="fname" class="form-control" placeholder="John"/>
</div>
<div class="form-group">
<label for="">Last Name</label>
<input type="text" name="lname" class="form-control" placeholder="Doe"/>
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" name="email" class="form-control" placeholder="[email protected]"/>
</div>
<div class="form-group">
<label for="">Gender</label>
<select name="gender">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="undefined">Undefined</option>
</select>
</div>
<div class="form-group">
<label for="">Password</label>
<input type="password" name="password" class="form-control"/>
</div>
<div class="form-group">
<label for="">Repeat Password</label>
<input type="password" name="repeat_password" class="form-control"/>
</div>
<div class="form-group">
<input type="submit" name="btnRegister" class="btn btn-primary" value="Register"/>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<footer id="footer">
<div class="footer_bottom">
<p class="copyright">Copyright © 2017 <a href="index.php">Matcha</a></p>
<p class="developer">Developed By kmuvezwa</p>
</div>
</footer>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/wow.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/slick.min.js"></script>
<script src="./assets/js/jquery.li-scroller.1.0.js"></script>
<script src="./assets/js/jquery.newsTicker.min.js"></script>
<script src="./assets/js/jquery.fancybox.pack.js"></script>
<script src="./assets/js/custom.js"></script>
</body>
</html>