1 |
1425
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package login
|
6 |
1782
|
Luisehahne
|
* @author Ryan Djurovich (2004-2009), WebsiteBaker Project
|
7 |
1709
|
Luisehahne
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8 |
1425
|
Luisehahne
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
|
|
* @requirements PHP 5.2.2 and higher
|
12 |
|
|
* @version $Id$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
|
|
// Include the configuration file
|
19 |
1833
|
Luisehahne
|
$config_file = realpath('../../../config.php');
|
20 |
|
|
if(file_exists($config_file) && !defined('WB_URL'))
|
21 |
|
|
{
|
22 |
|
|
require_once($config_file);
|
23 |
1709
|
Luisehahne
|
}
|
24 |
2098
|
darkviper
|
$oDb = WbDatabase::getInstance();
|
25 |
|
|
$oTrans = Translate::getInstance();
|
26 |
1425
|
Luisehahne
|
$admin = new admin('Start', 'start', false, false);
|
27 |
|
|
// Check if the user has already submitted the form, otherwise show it
|
28 |
1833
|
Luisehahne
|
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") {
|
29 |
1425
|
Luisehahne
|
$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
|
30 |
|
|
// Check if the email exists in the database
|
31 |
2098
|
darkviper
|
$sql = 'SELECT `user_id`, `username`, `display_name`, `email`, `last_reset`, `password` '
|
32 |
|
|
. 'FROM `'.$oDb->TablePrefix.'users` '
|
33 |
|
|
. 'WHERE `email`=\''.$admin->add_slashes($_POST['email']).'\'';
|
34 |
|
|
$results = $oDb->doQuery($sql);
|
35 |
|
|
if (($results_array = $results->fetchRow(MYSQL_ASSOC))) {
|
36 |
1425
|
Luisehahne
|
// Get the id, username, email, and last_reset from the above db query
|
37 |
|
|
// Check if the password has been reset in the last 2 hours
|
38 |
|
|
$last_reset = $results_array['last_reset'];
|
39 |
2098
|
darkviper
|
$time_diff = (time()-$last_reset) / (60 * 60); // Time since last reset in hours
|
40 |
1425
|
Luisehahne
|
if($time_diff < 2) {
|
41 |
|
|
// Tell the user that their password cannot be reset more than once per hour
|
42 |
2098
|
darkviper
|
$message = $oTrans->MESSAGE_FORGOT_PASS_ALREADY_RESET;
|
43 |
1425
|
Luisehahne
|
} else {
|
44 |
|
|
$old_pass = $results_array['password'];
|
45 |
|
|
// Generate a random password then update the database with it
|
46 |
2098
|
darkviper
|
$oPassword = new Password();
|
47 |
|
|
$new_pass = $oPassword->createNew(8, Password::PW_USE_ALL);
|
48 |
|
|
$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
|
49 |
|
|
. 'SET `password`=\''.md5($new_pass).'\', '
|
50 |
|
|
. '`last_reset`='.time().' '
|
51 |
|
|
. 'WHERE `user_id`='.(int)$results_array['user_id'];
|
52 |
|
|
if ($oDb->doQuery($sql)) {
|
53 |
1425
|
Luisehahne
|
// Setup email to send
|
54 |
|
|
$mail_to = $email;
|
55 |
2098
|
darkviper
|
$mail_subject = $oTrans->MESSAGE_SIGNUP2_SUBJECT_LOGIN_INFO;
|
56 |
1425
|
Luisehahne
|
// Replace placeholders from language variable with values
|
57 |
|
|
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
|
58 |
1709
|
Luisehahne
|
$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
|
59 |
2098
|
darkviper
|
$mail_message = str_replace($search, $replace, $oTrans->MESSAGE_SIGNUP2_BODY_LOGIN_FORGOT);
|
60 |
1425
|
Luisehahne
|
// Try sending the email
|
61 |
1709
|
Luisehahne
|
if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
|
62 |
2098
|
darkviper
|
$message = $oTrans->MESSAGE_FORGOT_PASS_PASSWORD_RESET;
|
63 |
1425
|
Luisehahne
|
$display_form = false;
|
64 |
|
|
} else {
|
65 |
2098
|
darkviper
|
$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
|
66 |
|
|
. 'SET `password`=\''.$old_pass.'\' '
|
67 |
|
|
. 'WHERE `user_id`='.(int)$results_array['user_id'];
|
68 |
|
|
$oDb->doQuery($sql);
|
69 |
|
|
$message = $oTrans->MESSAGE_FORGOT_PASS_CANNOT_EMAIL;
|
70 |
1425
|
Luisehahne
|
}
|
71 |
2098
|
darkviper
|
} else {
|
72 |
|
|
// Error updating database
|
73 |
|
|
$message = $oDb->getError();
|
74 |
|
|
}
|
75 |
1425
|
Luisehahne
|
}
|
76 |
|
|
} else {
|
77 |
|
|
// Email doesn't exist, so tell the user
|
78 |
2098
|
darkviper
|
$message = $oTrans->MESSAGE_FORGOT_PASS_EMAIL_NOT_FOUND;
|
79 |
1425
|
Luisehahne
|
// and delete the wrong Email
|
80 |
|
|
$email = '';
|
81 |
|
|
}
|
82 |
|
|
} else {
|
83 |
|
|
$email = '';
|
84 |
|
|
}
|
85 |
|
|
if(!isset($message)) {
|
86 |
2098
|
darkviper
|
$message = $oTrans->MESSAGE_FORGOT_PASS_NO_DATA;
|
87 |
1425
|
Luisehahne
|
$message_color = '000000';
|
88 |
|
|
} else {
|
89 |
|
|
$message_color = 'FF0000';
|
90 |
|
|
}
|
91 |
1709
|
Luisehahne
|
|
92 |
1529
|
Luisehahne
|
// Setup template object, parse vars to it, then parse it
|
93 |
|
|
// Create new template object
|
94 |
1709
|
Luisehahne
|
$template = new Template(dirname($admin->correct_theme_source('loginForgot.htt')));
|
95 |
|
|
$template->set_file('page', 'loginForgot.htt');
|
96 |
1425
|
Luisehahne
|
$template->set_block('page', 'main_block', 'main');
|
97 |
|
|
if(defined('FRONTEND')) {
|
98 |
|
|
$template->set_var('ACTION_URL', 'forgot.php');
|
99 |
|
|
} else {
|
100 |
|
|
$template->set_var('ACTION_URL', 'index.php');
|
101 |
|
|
}
|
102 |
|
|
$template->set_var('EMAIL', $email);
|
103 |
2098
|
darkviper
|
$template->set_var($oTrans->getLangArray());
|
104 |
1425
|
Luisehahne
|
if(isset($display_form)) {
|
105 |
|
|
$template->set_var('DISPLAY_FORM', 'display:none;');
|
106 |
|
|
}
|
107 |
|
|
$template->set_var(array(
|
108 |
2098
|
darkviper
|
'SECTION_FORGOT' => $oTrans->MENU_FORGOT,
|
109 |
|
|
'MESSAGE_COLOR' => $message_color,
|
110 |
|
|
'MESSAGE' => $message,
|
111 |
|
|
'WEBSITE_TITLE' => WEBSITE_TITLE,
|
112 |
|
|
'ADMIN_URL' => ADMIN_URL,
|
113 |
|
|
'WB_URL' => WB_URL,
|
114 |
|
|
'URL_VIEW' => WB_URL,
|
115 |
|
|
'THEME_URL' => THEME_URL,
|
116 |
|
|
'VERSION' => VERSION,
|
117 |
|
|
'SP' => (defined('SP') ? SP : ''),
|
118 |
|
|
'REVISION' => REVISION,
|
119 |
|
|
'LANGUAGE' => strtolower(LANGUAGE),
|
120 |
|
|
'LOGIN_ICON' => 'login',
|
121 |
|
|
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
|
122 |
|
|
'START_ICON' => 'blank',
|
123 |
|
|
'LOGIN_DISPLAY_HIDDEN' => !$admin->is_authenticated() ? 'hidden' : '',
|
124 |
|
|
'LOGIN_DISPLAY_NONE' => !$admin->is_authenticated() ? 'none' : '',
|
125 |
|
|
'URL_HELP' => 'http://www.websitebaker.org/',
|
126 |
|
|
'URL' => ADMIN_URL."/start/index.php"
|
127 |
|
|
)
|
128 |
|
|
);
|
129 |
1425
|
Luisehahne
|
|
130 |
|
|
if(defined('FRONTEND')) {
|
131 |
|
|
$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
|
132 |
|
|
} else {
|
133 |
|
|
$template->set_var('LOGIN_URL', ADMIN_URL);
|
134 |
|
|
}
|
135 |
1709
|
Luisehahne
|
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');
|
136 |
1425
|
Luisehahne
|
|
137 |
|
|
if(defined('DEFAULT_CHARSET')) {
|
138 |
|
|
$charset=DEFAULT_CHARSET;
|
139 |
|
|
} else {
|
140 |
|
|
$charset='utf-8';
|
141 |
|
|
}
|
142 |
|
|
|
143 |
1709
|
Luisehahne
|
$template->set_var('CHARSET', $charset);
|
144 |
1425
|
Luisehahne
|
|
145 |
|
|
$template->parse('main', 'main_block', false);
|
146 |
|
|
$template->pparse('output', 'page');
|
147 |
1709
|
Luisehahne
|
|
148 |
|
|
//$admin->print_footer();
|