This repository was archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivate.php
More file actions
147 lines (111 loc) · 4.69 KB
/
activate.php
File metadata and controls
147 lines (111 loc) · 4.69 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
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
<?php
include_once('./templates/globals.php');
$pageTitle = 'Page Title';
$pageHeader = 'Page Header';
$pageStyles = array();
$activeTab = '0';
$pageScripts = array();
$PageScriptsRaw = '';
include_once('./templates/header.php');
include_once ('classes/class.generic.php');
class Activate extends Generic {
private $key;
private $user;
private $error;
function __construct() {
// Assign their username to a variable
if(isset($_SESSION['username']))
$this->user = $_SESSION['username'];
// Are they clicking from an email?
if(isset($_GET['key'])) {
$this->key = parent::secure($_GET['key']);
$this->getKey();
// Do they want the key resent?
} else if(isset($_GET['resend']) && $_GET['resend'] == '1') {
$this->resendKey();
// Are they already signed in without a key?
} else if(isset($this->user) && !isset($this->key)) {
$this->signedIn();
} else header('location: index.php');
// Display any errors
parent::displayErrors($this->error, false);
}
private function getKey() {
$result = parent::query("SELECT login_activate.email,login_activate.username, login_users.name
FROM login_activate, login_users
WHERE login_activate.code='$this->key'
AND login_activate.username = login_users.username");
$rowCheck = mysql_num_rows($result);
if ($rowCheck != 0) {
$row = mysql_fetch_array($result);
$username = $row['username'];
$to = $row['email'];
// Activate by deleting the activation code
parent::query("DELETE FROM login_activate WHERE username='$username'");
// Set user's activate session to false
if(!empty($_SESSION['activate'])) unset($_SESSION['activate']);
echo "<div class=\"alert alert-success\">"._('Your account has been activated!')."</div>" ._('You can now see the default access granted to new users.')."
<p>"._('If you require more access please contact the site admin at')." " . address . "</p>
<h5>"._('What to do now?')."</h5>
<p>" . sprintf(_('Go to the <a href="%s"> homepage</a>'), 'index.php') . "</p>";
$shortcodes = array(
'site_address' => SITE_PATH,
'full_name' => $row['name'],
'username' => $username
);
$msg = parent::getOption('email-activate-msg');
$subj = parent::getOption('email-activate-subj');
if(!parent::sendEmail($to, $subj, $msg, $shortcodes))
$this->error = "ERROR. Mail not sent";
} else {
$this->error = "<div class=\"alert alert-error\">"._('Your activation link is incorrect.')."</div>
<h5>"._('What to do now?')."</h5>
<p>" . sprintf(_('Go to the <a href="%s"> homepage</a>'), 'index.php') . "</p>";
}
}
private function resendKey() {
$result = parent::query("SELECT login_activate.email,login_activate.username, login_activate.code, login_users.name
FROM login_activate, login_users
WHERE login_activate.username='$this->user'
AND login_users.username ='$this->user'");
$row = mysql_fetch_array($result);
$code = $row['code'];
if (!empty($code)) {
$shortcodes = array(
'site_address' => SITE_PATH,
'full_name' => $row['name'],
'username' => $this->user,
'activate' => SITE_PATH . "activate.php?key=$code"
);
$subj = parent::getOption('email-activate-resend-subj');
$msg = parent::getOption('email-activate-resend-msg');
$to = $row['email'];
if(parent::sendEmail($to, $subj, $msg, $shortcodes)) {
$this->error = "<div class=\"alert alert-success\">"._('Activation link resent to email.')."</div>
<h5>"._('What to do now?')."</h5>"
._('Click the link in your email to activate your account.')." ";
} else $this->error = _('ERROR. Mail not sent');
} else {
$this->error = "<div class=\"alert alert-error\">"._('You do not have an activation code!')."</div>
<p>"._('Please contact an admin:')." " . address . "</p>";
}
}
private function signedIn() {
// Check if user needs activation
$sql = "SELECT * FROM login_activate WHERE username='$this->user'";
$rowCheck = parent::numRows($sql);
if ($rowCheck < 1) {
$this->error = "<div class=\"alert alert-error\">"._('Your account has already been activated.')."</div>
<h5>"._('What to do now?')."</h5>
<p>" . sprintf(_('Go to the <a href="%s"> homepage</a>'), 'index.php') . "</p>";
} else {
$this->error = "<div class=\"alert alert-error\">"._('You have not activated your account yet.')."</div>
<h5>"._('What to do now?')."</h5>"
._('Please follow the link in your email to activate your account.')."<br/><br/>"
._('Would you like us to')." <a href='activate.php?resend=1'>"._('resend')."</a>" ._('the link?');
}
}
}
$activate = new Activate;
include_once('./templates/footer.php');
?>