-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignupconfirm.php
90 lines (82 loc) · 3.01 KB
/
signupconfirm.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
<?php
require "util/db.php";
require "util/util.php";
session_start();
if(!isset($_SESSION["isverified"]))
{
// NOT logged in
header("Location: login.php");
return;
}
print($_SESSION["userid"]);
// if($_SESSION["isverified"] == true)
// {
// header("Location: index.php");
// return;
// }
$db = new DB;
$db_obj = $db->create_db(3306,"fundraising","root","");
$err="";
if(isset($_POST["email"]) && isset($_POST["code"]))
{
// print_r($_POST["email"]);
//GET USERID USING EMAIL
$stml = $db_obj->prepare("SELECT userID from users WHERE emailId = :email");
$stml->bindParam(':email',$_POST["email"],PDO::PARAM_STR);
$stml->execute();
$userid = $stml->fetchAll(PDO::FETCH_ASSOC);
if(isset($userid[0])){
//If email entered was able to find a user
$userid = $userid[0]["userID"];
//GET e_code using $userid from above
$stml = $db_obj->prepare("SELECT e_code from emailverify WHERE userid = :id");
$stml->execute(array(':id' => $userid));
$ecode = $stml->fetchAll(PDO::FETCH_ASSOC);
$ecode = $ecode[0]["e_code"];
$user_code =str_split($_POST["code"],10)[0];
//Check if enterd code matches ecode
if(!strcmp($ecode, $user_code))
{
// SUCCESSFUL
// UPDATE emailverify SET e_code = "1001" WHERE userid = 23;
$stml = $db_obj->prepare("UPDATE emailverify SET isverified = 1 WHERE userid = :id;");
if($stml->execute(array(':id' => $userid))){
//DONE
$_SESSION["isverified"] = true;
}else{
$err = "Please try again.";
}
}else{
$err = "Please enter a valid code";
}
}
else{
$err = "Enter valid email and code";
}
}else{
$err = "Please enter email and code";
}
?>
<?php
require "templates/top.php";
if($_SESSION["isverified"] == true)
{
echo('<h1 class="mt-4 ml-4">Thank you for confirming</h1>');
echo('<button class="btn btn-danger ml-4"><a href="dashboard.php" style="text-decoration: none;">Go to dashboard</a></button>');
}else{
echo('<div class="container" style="width: 30%;margin-top: 5em;"><form method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Code</label>
<input type="text" class="form-control" name="code" placeholder="Enter code">
</div>
<button type="submit" class="btn btn-danger">Submit</button>
</form>
<div class="mt-2"><p style="color:red;font-size="15px>'.$err.'</p></div>
</div>');
}
require "templates/foot.php";
?>