-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
68 lines (56 loc) · 2.79 KB
/
signup.php
File metadata and controls
68 lines (56 loc) · 2.79 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
<?php
/* this code lives on the header.php on the top of the html */
require_once('includes/config.php');
require_once('includes/functions.php');
require_once('includes/password.php');
// Registration Page
//echo json_encode(['message' => 'udeme is a boy']);
//if (isset($_POST['register'])) {
$credentials = [
'firstname'=>$_POST['firstname'],
'lastname'=>$_POST['lastname'],
'email'=>$_POST['email'],
'password'=>$_POST['password'],
'vpassword'=>$_POST['vpassword']
];
if($credentials['vpassword'] !== $credentials['password']){
$validation_response = "<div class='alert alert-danger'>Passwords are not the same</div>";
echo json_encode(['message' => $validation_response]);
//echo /*json_encode(['message' => $validation_response])*/;
}else{
$hashed_pass = password_hash($credentials['password'], PASSWORD_BCRYPT);
try {
$check = $conn->prepare('SELECT * FROM `users` WHERE `email` = :email');
$check->execute([':email'=>$credentials['email']]);
if($check->rowCount() === 1){
$validation_response = "<div class='alert alert-danger'>User Already Exists</div>";
echo json_encode(['message' => $validation_response]);
}else{
$bind = [':firstname'=>$credentials['firstname'],':lastname'=>$credentials['lastname'],
':email'=>$credentials['email'],':password'=>$hashed_pass];
$query = "INSERT INTO `users` (firstname, lastname, email, password)
VALUES (:firstname, :lastname, :email, :password)";
$stmt = $conn->prepare($query);
$stmt->execute($bind);
$recipient = $credentials['email'];
$sender = 'no-reply@foivault.com';
$subject = 'Foivault Registration';
$mail_body = "Click the link to activate your Foivault account\n <a href='".
base64_encode($credentials['email'].$credentials['firstname'])."'>Click Me</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$sender."\r\n";
$headers .= 'Reply-To: '.$sender."\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion();
mail($recipient,$subject,$mail_body,$headers);
$validation_response = "<div class='alert alert-success'>Check your email to confirm your account</div>";
echo json_encode(['message' => $validation_response]);
}
}catch(PDOException $e){
// echo 'Connection Error: ' . $e->getMessage();
$err = 'Connection Error: ' . $e->getMessage();
echo json_encode(['message' => $err]);
}
}
//}
?>