Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         login
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @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: index.php 1833 2012-12-10 04:05:38Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2012-12-10 05:05:38 +0100 (Mon, 10 Dec 2012) $
15
 *
16
*/
17

    
18
// Include the configuration file
19
$config_file = realpath('../../../config.php');
20
if(file_exists($config_file) && !defined('WB_URL'))
21
{
22
	require_once($config_file);
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'); }
31
$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
// Check if the user has already submitted the form, otherwise show it
39

    
40
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") {
41

    
42
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
43

    
44
	// 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
		$results_array = $results->fetchRow(MYSQL_ASSOC);
51

    
52
		// 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

    
58
			// Tell the user that their password cannot be reset more than once per hour
59
			$message = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
60

    
61
		} else {
62

    
63
			$old_pass = $results_array['password'];
64

    
65
			// 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 {
83
				// Setup email to send
84
				$mail_to = $email;
85
				$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
86

    
87
				// Replace placeholders from language variable with values
88
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
89
				$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

    
92
				// Try sending the email
93
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
94
					$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
95
					$display_form = false;
96
				} 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'];
99
				}
100
			}
101

    
102
		}
103

    
104
	} else {
105
		// Email doesn't exist, so tell the user
106
		$message = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
107
		// and delete the wrong Email
108
		$email = '';
109
	}
110

    
111
} else {
112
	$email = '';
113
}
114

    
115
if(!isset($message)) {
116
	$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
117
	$message_color = '000000';
118
} else {
119
	$message_color = 'FF0000';
120
}
121

    
122
// Setup template object, parse vars to it, then parse it
123
// Create new template object
124
$template = new Template(dirname($admin->correct_theme_source('loginForgot.htt')));
125
$template->set_file('page', 'loginForgot.htt');
126
$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
				'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
		);
169

    
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
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');
176

    
177
if(defined('DEFAULT_CHARSET')) {
178
	$charset=DEFAULT_CHARSET;
179
} else {
180
	$charset='utf-8';
181
}
182

    
183
$template->set_var('CHARSET', $charset);
184

    
185
$template->parse('main', 'main_block', false);
186
$template->pparse('output', 'page');
187

    
188
//$admin->print_footer();
    (1-1/1)