Project

General

Profile

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