Revision 2098
Added by darkviper over 10 years ago
index.php | ||
---|---|---|
21 | 21 |
{ |
22 | 22 |
require_once($config_file); |
23 | 23 |
} |
24 |
// Include the language file |
|
25 |
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php'); |
|
26 |
|
|
27 |
// Include the database class file and initiate an object |
|
28 |
//if(!class_exists('frontend', false)){ require_once(WB_PATH.'/framework/class.frontend.php'); } |
|
29 |
//$admin = new frontend(); |
|
30 |
if(!class_exists('admin', false)){ require_once(WB_PATH.'/framework/class.admin.php'); } |
|
24 |
$oDb = WbDatabase::getInstance(); |
|
25 |
$oTrans = Translate::getInstance(); |
|
31 | 26 |
$admin = new admin('Start', 'start', false, false); |
32 |
|
|
33 |
// Get the website title |
|
34 |
$results = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'"); |
|
35 |
$results = $results->fetchRow(MYSQL_ASSOC); |
|
36 |
$website_title = $results['value']; |
|
37 |
|
|
38 | 27 |
// Check if the user has already submitted the form, otherwise show it |
39 |
|
|
40 | 28 |
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") { |
41 |
|
|
42 | 29 |
$email = htmlspecialchars($_POST['email'],ENT_QUOTES); |
43 |
|
|
44 | 30 |
// Check if the email exists in the database |
45 |
$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'"; |
|
46 |
$results = $database->query($query); |
|
47 |
if($results->numRows() > 0) { |
|
48 |
|
|
31 |
$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))) { |
|
49 | 36 |
// Get the id, username, email, and last_reset from the above db query |
50 |
$results_array = $results->fetchRow(MYSQL_ASSOC); |
|
51 |
|
|
52 | 37 |
// Check if the password has been reset in the last 2 hours |
53 | 38 |
$last_reset = $results_array['last_reset']; |
54 |
$time_diff = time()-$last_reset; // Time since last reset in seconds |
|
55 |
$time_diff = $time_diff/60/60; // Time since last reset in hours |
|
39 |
$time_diff = (time()-$last_reset) / (60 * 60); // Time since last reset in hours |
|
56 | 40 |
if($time_diff < 2) { |
57 |
|
|
58 | 41 |
// Tell the user that their password cannot be reset more than once per hour |
59 |
$message = $MESSAGE['FORGOT_PASS_ALREADY_RESET']; |
|
60 |
|
|
42 |
$message = $oTrans->MESSAGE_FORGOT_PASS_ALREADY_RESET; |
|
61 | 43 |
} else { |
62 |
|
|
63 | 44 |
$old_pass = $results_array['password']; |
64 |
|
|
65 | 45 |
// Generate a random password then update the database with it |
66 |
$new_pass = ''; |
|
67 |
$salt = "abchefghjkmnpqrstuvwxyz0123456789"; |
|
68 |
srand((double)microtime()*1000000); |
|
69 |
$i = 0; |
|
70 |
while ($i <= 7) { |
|
71 |
$num = rand() % 33; |
|
72 |
$tmp = substr($salt, $num, 1); |
|
73 |
$new_pass = $new_pass . $tmp; |
|
74 |
$i++; |
|
75 |
} |
|
76 |
|
|
77 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'"); |
|
78 |
|
|
79 |
if($database->is_error()) { |
|
80 |
// Error updating database |
|
81 |
$message = $database->get_error(); |
|
82 |
} else { |
|
46 |
$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)) { |
|
83 | 53 |
// Setup email to send |
84 | 54 |
$mail_to = $email; |
85 |
$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO']; |
|
86 |
|
|
55 |
$mail_subject = $oTrans->MESSAGE_SIGNUP2_SUBJECT_LOGIN_INFO; |
|
87 | 56 |
// Replace placeholders from language variable with values |
88 | 57 |
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}'); |
89 | 58 |
$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); |
90 |
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']); |
|
91 |
|
|
59 |
$mail_message = str_replace($search, $replace, $oTrans->MESSAGE_SIGNUP2_BODY_LOGIN_FORGOT); |
|
92 | 60 |
// Try sending the email |
93 | 61 |
if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { |
94 |
$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
|
|
62 |
$message = $oTrans->MESSAGE_FORGOT_PASS_PASSWORD_RESET;
|
|
95 | 63 |
$display_form = false; |
96 | 64 |
} else { |
97 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'"); |
|
98 |
$message = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL']; |
|
65 |
$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; |
|
99 | 70 |
} |
100 |
} |
|
101 |
|
|
71 |
} else { |
|
72 |
// Error updating database |
|
73 |
$message = $oDb->getError(); |
|
74 |
} |
|
102 | 75 |
} |
103 |
|
|
104 | 76 |
} else { |
105 | 77 |
// Email doesn't exist, so tell the user |
106 |
$message = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
|
|
78 |
$message = $oTrans->MESSAGE_FORGOT_PASS_EMAIL_NOT_FOUND;
|
|
107 | 79 |
// and delete the wrong Email |
108 | 80 |
$email = ''; |
109 | 81 |
} |
110 |
|
|
111 | 82 |
} else { |
112 | 83 |
$email = ''; |
113 | 84 |
} |
114 |
|
|
115 | 85 |
if(!isset($message)) { |
116 |
$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
|
|
86 |
$message = $oTrans->MESSAGE_FORGOT_PASS_NO_DATA;
|
|
117 | 87 |
$message_color = '000000'; |
118 | 88 |
} else { |
119 | 89 |
$message_color = 'FF0000'; |
... | ... | |
130 | 100 |
$template->set_var('ACTION_URL', 'index.php'); |
131 | 101 |
} |
132 | 102 |
$template->set_var('EMAIL', $email); |
133 |
|
|
103 |
$template->set_var($oTrans->getLangArray()); |
|
134 | 104 |
if(isset($display_form)) { |
135 | 105 |
$template->set_var('DISPLAY_FORM', 'display:none;'); |
136 | 106 |
} |
137 |
|
|
138 | 107 |
$template->set_var(array( |
139 |
'SECTION_FORGOT' => $MENU['FORGOT'], |
|
140 |
'MESSAGE_COLOR' => $message_color, |
|
141 |
'MESSAGE' => $message, |
|
142 |
'WEBSITE_TITLE' => WEBSITE_TITLE, |
|
143 |
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'], |
|
144 |
'ADMIN_URL' => ADMIN_URL, |
|
145 |
'WB_URL' => WB_URL, |
|
146 |
'URL_VIEW' => WB_URL, |
|
147 |
'THEME_URL' => THEME_URL, |
|
148 |
'VERSION' => VERSION, |
|
149 |
'SP' => (defined('SP') ? SP : ''), |
|
150 |
'REVISION' => REVISION, |
|
151 |
'LANGUAGE' => strtolower(LANGUAGE), |
|
152 |
'TEXT_EMAIL' => $TEXT['EMAIL'], |
|
153 |
'TEXT_SEND_DETAILS' => $TEXT['SEND_DETAILS'], |
|
154 |
'TEXT_LOGIN' => $TEXT['LOGIN'], |
|
155 |
'TITLE_LOGOUT' => $MENU['LOGIN'], |
|
156 |
'TEXT_RESET' => $TEXT['RESET'], |
|
157 |
'TEXT_HOME' => $TEXT['HOME'], |
|
158 |
'TITLE_VIEW' => $TEXT['WEBSITE'], |
|
159 |
'LOGIN_ICON' => 'login', |
|
160 |
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'], |
|
161 |
'START_ICON' => 'blank', |
|
162 |
'LOGIN_DISPLAY_HIDDEN' => !$admin->is_authenticated() ? 'hidden' : '', |
|
163 |
'LOGIN_DISPLAY_NONE' => !$admin->is_authenticated() ? 'none' : '', |
|
164 |
'URL_HELP' => 'http://www.websitebaker.org/', |
|
165 |
'URL' => ADMIN_URL."/start/index.php", |
|
166 |
'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN'] |
|
167 |
) |
|
168 |
); |
|
108 |
'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 |
); |
|
169 | 129 |
|
170 | 130 |
if(defined('FRONTEND')) { |
171 | 131 |
$template->set_var('LOGIN_URL', WB_URL.'/account/login.php'); |
Also available in: Unified diff
! activate class Translate for all addons in admin/ (except pages/)
! class.admin >> add translation of the current theme to Translate