-
Notifications
You must be signed in to change notification settings - Fork 4
/
activate.php
97 lines (86 loc) · 2.9 KB
/
activate.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
<?php include 'includes/session.php'; ?>
<?php
$output = '';
if(!isset($_GET['code']) OR !isset($_GET['user'])){
$output .= '
<div class="alert alert-danger">
<h4><i class="icon fa fa-warning"></i> Error!</h4>
Code to activate account not found.
</div>
<h4>You may <a href="signup.php">Signup</a> or back to <a href="index.php">Homepage</a>.</h4>
';
}
else{
$conn = $pdo->open();
$stmt = $conn->prepare("SELECT *, COUNT(*) AS numrows FROM users WHERE activate_code=:code AND id=:id");
$stmt->execute(['code'=>$_GET['code'], 'id'=>$_GET['user']]);
$row = $stmt->fetch();
if($row['numrows'] > 0){
if($row['status']){
$output .= '
<div class="alert alert-danger">
<h4><i class="icon fa fa-warning"></i> Error!</h4>
Account already activated.
</div>
<h4>You may <a href="login.php">Login</a> or back to <a href="index.php">Homepage</a>.</h4>
';
}
else{
try{
$stmt = $conn->prepare("UPDATE users SET status=:status WHERE id=:id");
$stmt->execute(['status'=>1, 'id'=>$row['id']]);
$output .= '
<div class="alert alert-success">
<h4><i class="icon fa fa-check"></i> Success!</h4>
Account activated - Email: <b>'.$row['email'].'</b>.
</div>
<h4>You may <a href="login.php">Login</a> or back to <a href="index.php">Homepage</a>.</h4>
';
}
catch(PDOException $e){
$output .= '
<div class="alert alert-danger">
<h4><i class="icon fa fa-warning"></i> Error!</h4>
'.$e->getMessage().'
</div>
<h4>You may <a href="signup.php">Signup</a> or back to <a href="index.php">Homepage</a>.</h4>
';
}
}
}
else{
$output .= '
<div class="alert alert-danger">
<h4><i class="icon fa fa-warning"></i> Error!</h4>
Cannot activate account. Wrong code.
</div>
<h4>You may <a href="signup.php">Signup</a> or back to <a href="index.php">Homepage</a>.</h4>
';
}
$pdo->close();
}
?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition skin-blue layout-top-nav">
<div class="wrapper">
<?php include 'includes/navbar.php'; ?>
<div class="content-wrapper">
<div class="container">
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-sm-9">
<?php echo $output; ?>
</div>
<div class="col-sm-3">
<?php include 'includes/sidebar.php'; ?>
</div>
</div>
</section>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</div>
<?php include 'includes/scripts.php'; ?>
</body>
</html>