-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.php
165 lines (155 loc) · 8.44 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
<?php
session_start();
$showError = (isset($showError)) ? $showError : false;
$existingUserErr = (isset($existingUserErr))?$existingUserErr:false;
if($_SERVER["REQUEST_METHOD"] == "POST") {
$fullname = $_POST["fullName"];
$email = $_POST["email"];
$pass = $_POST["password"];
$contact_number = $_POST["contactNumber"];
$birth_date = $_POST["birthDate"];
session_destroy();
if(require 'connection.php')
{
$userExistQuery = "select * from users where email='$email';";
$res = mysqli_query($conn, $userExistQuery);
if($res) {
$_SESSION["RES"] = mysqli_num_rows($res);
if(!mysqli_num_rows($res)){
setcookie("userExistErr", "", time() - 3600);
$query = "INSERT INTO `users`(`full_name`, `email`, `password`, `contact_number`, `birth_date`) VALUES ('$fullname','$email', MD5('$pass'), '$contact_number', '$birth_date');";
if(mysqli_query($conn, $query)) {
$id = mysqli_insert_id($conn);
$mail_body = '<html>
<body>
<h1>👋 Welcome To Expeny!</h1>
<p>After this step you\'ll be able to start manage your expenses.</p>
<p>To ensure you\'re legitimate and not some fake bot, please verify your account by clicking <a href="http://localhost:8080/Expeny/verify.php?id='.$id.'">here</a>.</p>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: Expeny<[email protected]>' . "\r\n";
if(mail($email, "Expeny - Verify Account", $mail_body, $headers))
{
setcookie("UNVERIFIED_EMAIL", $email);
header("location: signup.php");
} else {}
}
} else {
setcookie("userExistErr",$email);
header("location: signup.php");
}
}
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Join Expeny Now</title>
<link rel="icon" type="image/png" href="assets/images/favicon.svg"/>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body id="signUp">
<div class="container-fluid signUpContainer">
<div class="row">
<div class="col-12 col-lg-6 signUpImgContainer m-0 p-0">
</div>
<div class="col-12 col-lg-6 d-flex justify-content-center align-items-center formContent">
<form method="POST" action="signup.php" id="signUpForm" class="col-10 col-lg-6">
<h4 class="pageHeader">Sign Up</h4>
<?php
if(isset($_COOKIE['UNVERIFIED_EMAIL']))
{
echo '<div class="mb-3">
<div class="alert alert-primary" role="alert" data-bs-toggle="tooltip" data-bs-placement="top" title="verify email from '.$_COOKIE["UNVERIFIED_EMAIL"].'">
<i class="fas fa-info-circle"></i>
<span class="pl-2">Please verify your email.</span>
</div>
</div>';
}
?>
<?php
if(isset($_COOKIE["userExistErr"]))
{
echo '<div class="mb-3">
<div class="alert alert-danger" role="alert" data-bs-toggle="tooltip" data-bs-placement="top" title="email '.$_COOKIE["userExistErr"].' is already exist.">
<i class="fas fa-exclamation-triangle"></i>
<span class="pl-2">Email already exist.</span>
</div>
</div>';
}
?>
<div class="mb-3">
<label for="fullName" class="form-label">Full Name</label>
<input type="text" class="form-control" id="fullName" name="fullName" autocomplete="off">
<div class="d-none" id="fullNameError">
Please Enter Fullname.
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="text" class="form-control" id="email" name="email" autocomplete="off">
<div class="d-none" id="emailError">
Invaid email.
</div>
<?php
if ($existingUserErr) {
echo '<div class="d-none" id="passwordError">Email address already in use.</div>';
}
?>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" autocomplete="off">
<div class="d-none" id="passwordError">
Please fill password field.
</div>
</div>
<div class="mb-3">
<label for="confirmPassword" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" autocomplete="off">
<div class="d-none" id="noMatchError">
Password and Confirm Password must be same.
</div>
</div>
<div class="mb-3">
<label for="contactNumber" class="form-label">Contact Number</label>
<input type="text" class="form-control" id="contactNumber" name="contactNumber" autocomplete="off">
<div class="d-none" id="`1">
Please fill contact number.
</div>
<div class="d-none" id="invalidNumberError">
Please Enter 10 digit number only.
</div>
</div>
<div class="mb-3">
<label for="birthDate" class="form-label">Birth Date</label>
<input type="date" class="form-control" id="birthDate" name="birthDate" >
<div class="d-none" id="birthDateError">
Please fill birth date field.
</div>
<div class="d-none" id="ageError">
your age must be greater than 15 year .
</div>
</div>
<button type="submit" class="btn btn-primary primaryBtn" id="validateSignUp">Register</button>
<span class="mx-3 signinLink"><a href="signin.php">Already Registered?</a></span>
</form>
</div>
</div>
</div>
</body>
<script src="assets/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="assets/js/main.js"></script>
</html>