forked from GeniXCMS/GeniXCMS
/
forgotpassword.php
147 lines (130 loc) · 3.47 KB
/
forgotpassword.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
<?php
/**
* GeniXCMS - Content Management System
*
* PHP Based Content Management System and Framework
*
* @package GeniXCMS
* @since 0.0.1 build date 20140928
* @version 0.0.6
* @link https://github.com/semplon/GeniXCMS
* @link http://genixcms.org
* @author Puguh Wijayanto (www.metalgenix.com)
* @copyright 2014-2015 Puguh Wijayanto
* @license http://www.opensource.org/licenses/mit-license.php MIT
*
*/
define('GX_PATH', realpath(__DIR__ . '/'));
define('GX_LIB', GX_PATH.'/inc/lib/');
define('GX_MOD', GX_PATH.'/inc/mod/');
define('GX_THEME', GX_PATH.'/inc/themes/');
define('GX_ASSET', GX_PATH.'/assets/');
require("autoload.php");
try {
new System();
} catch (Exception $e) {
echo $e->getMessage();
}
if(isset($_POST['forgotpass']))
{
// Check token first
if(isset($_POST['token']) && Token::isExist($_POST['token'])){
/*check if username is exist or not */
$username = Typo::cleanX(Typo::strip($_POST['username']));
$sql = sprintf("SELECT `userid`,`email`,`status`,`activation` FROM `user` WHERE `userid` = '%s'", $username);
$usr = Db::result($sql);
$c = Db::$num_rows;
//echo $c;
//print_r($usr);
if($c == "1"){
//$alertgreen = "";
// check if user is active
if($usr[0]->status == '1') {
/* get user password */
$newpass = User::generatePass();
$id = User::id($username);
$pass = User::randpass($newpass);
$vars = array(
'id' => $id,
'user' => array(
'pass' => $pass
)
);
User::update($vars);
$date = Date::format(date("Y-m-d H:i:s"));
$msg = "
Hello {$usr[0]->userid},
You are requesting Password Reset at ".Site::$name." on {$date}.
Below are your new Password :
{$newpass}
Now you can login with your new Password at ".Site::$url."
Best Regards,
".Site::$name."
".Site::$email."
";
$vars = array(
'to' => $usr[0]->email,
'to_name' => $usr[0]->userid,
'message' => $msg,
'subject' => 'Password Reset at '.Site::$name,
'msgtype' => 'text'
);
//echo "<pre>".$msg."</pre>";
if(Mail::send($vars)){
$alertgreen = PASSWORD_SENT_NOTIF;
}
}else{
if($usr[0]->activation != ''){
$alertred[] = ACOUNT_NOT_ACTIVE;
}else{
$alertred[] = ACOUNT_NOT_ACTIVE_BLOCK;
}
}
}elseif($c == "0"){
$alertred[] = NO_USER;
}
Token::remove($_POST['token']);
}else{
$alertred[] = TOKEN_NOT_EXIST;
}
}
Theme::theme('header');
if(isset($alertred)) {
echo "
<div class=\"alert alert-danger\">
";
foreach($alertred as $alert)
{
echo $alert;
}
echo"
</div>";
}
if(isset($alertgreen)) {
echo "
<div class=\"alert alert-success\">
{$alertgreen}
</div>";
}
if(!User::is_loggedin()){
?>
<div class="container">
<div style="max-width: 300px; margin-left: auto; margin-right: auto; margin-top: 30px; margin-bottom: 60px ">
<form action="" class="form-signin" role="form" method="post">
<h2 class="form-signin-heading"><?=FORGOT_PASS;?></h2>
<div class="form-group">
<label><?=FILLIN_USERNAME;?></label>
<input type="text" name="username" class="form-control" placeholder="<?=USERNAME;?>" required autofocus>
</div>
<input type="hidden" name="token" value="<?=TOKEN;?>">
<button class="btn btn-lg btn-success btn-block" name="forgotpass" type="submit"><?=REQUEST_PASS;?></button>
</form>
</div>
</div>
<?php
}else {
echo"<div class=\"alert alert-info\">You're already Logged In. <br /><a href=\"logout.php\">Logout</a></div>";
}
Theme::theme('footer');
System::Zipped();
?>