Project

General

Profile

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