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 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 1425 Luisehahne
// Include the language file
25
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
26 1782 Luisehahne
27 1425 Luisehahne
// Include the database class file and initiate an object
28 1782 Luisehahne
//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'); }
31 1425 Luisehahne
$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 1709 Luisehahne
$results = $results->fetchRow(MYSQL_ASSOC);
36 1425 Luisehahne
$website_title = $results['value'];
37
38
// Check if the user has already submitted the form, otherwise show it
39 1709 Luisehahne
40 1833 Luisehahne
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") {
41
42 1425 Luisehahne
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
43 1709 Luisehahne
44 1425 Luisehahne
	// 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
49
		// Get the id, username, email, and last_reset from the above db query
50 1709 Luisehahne
		$results_array = $results->fetchRow(MYSQL_ASSOC);
51
52 1425 Luisehahne
		// Check if the password has been reset in the last 2 hours
53
		$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
56
		if($time_diff < 2) {
57 1709 Luisehahne
58 1425 Luisehahne
			// Tell the user that their password cannot be reset more than once per hour
59 1782 Luisehahne
			$message = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
60 1709 Luisehahne
61 1425 Luisehahne
		} else {
62 1709 Luisehahne
63 1425 Luisehahne
			$old_pass = $results_array['password'];
64 1709 Luisehahne
65 1425 Luisehahne
			// 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 1709 Luisehahne
77 1425 Luisehahne
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
78 1709 Luisehahne
79 1425 Luisehahne
			if($database->is_error()) {
80
				// Error updating database
81
				$message = $database->get_error();
82
			} else {
83
				// Setup email to send
84
				$mail_to = $email;
85 1782 Luisehahne
				$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
86 1425 Luisehahne
87
				// Replace placeholders from language variable with values
88
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
89 1709 Luisehahne
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
90 1782 Luisehahne
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
91 1425 Luisehahne
92
				// Try sending the email
93 1709 Luisehahne
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
94 1782 Luisehahne
					$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
95 1425 Luisehahne
					$display_form = false;
96
				} else {
97
					$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
98 1782 Luisehahne
					$message = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
99 1425 Luisehahne
				}
100
			}
101 1709 Luisehahne
102 1425 Luisehahne
		}
103 1709 Luisehahne
104 1425 Luisehahne
	} else {
105
		// Email doesn't exist, so tell the user
106 1782 Luisehahne
		$message = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
107 1425 Luisehahne
		// and delete the wrong Email
108
		$email = '';
109
	}
110 1709 Luisehahne
111 1425 Luisehahne
} else {
112
	$email = '';
113
}
114
115
if(!isset($message)) {
116 1782 Luisehahne
	$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
117 1425 Luisehahne
	$message_color = '000000';
118
} else {
119
	$message_color = 'FF0000';
120
}
121 1709 Luisehahne
122 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
123
// Create new template object
124 1709 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('loginForgot.htt')));
125
$template->set_file('page', 'loginForgot.htt');
126 1425 Luisehahne
$template->set_block('page', 'main_block', 'main');
127
if(defined('FRONTEND')) {
128
	$template->set_var('ACTION_URL', 'forgot.php');
129
} else {
130
	$template->set_var('ACTION_URL', 'index.php');
131
}
132
$template->set_var('EMAIL', $email);
133
134
if(isset($display_form)) {
135
	$template->set_var('DISPLAY_FORM', 'display:none;');
136
}
137
138
$template->set_var(array(
139 1709 Luisehahne
				'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 1833 Luisehahne
				'URL' => ADMIN_URL."/start/index.php",
166 1709 Luisehahne
				'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN']
167
				)
168
		);
169 1425 Luisehahne
170
if(defined('FRONTEND')) {
171
	$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
172
} else {
173
	$template->set_var('LOGIN_URL', ADMIN_URL);
174
}
175 1709 Luisehahne
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');
176 1425 Luisehahne
177
if(defined('DEFAULT_CHARSET')) {
178
	$charset=DEFAULT_CHARSET;
179
} else {
180
	$charset='utf-8';
181
}
182
183 1709 Luisehahne
$template->set_var('CHARSET', $charset);
184 1425 Luisehahne
185
$template->parse('main', 'main_block', false);
186
$template->pparse('output', 'page');
187 1709 Luisehahne
188
//$admin->print_footer();