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 1782 2012-10-11 12:29:11Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2012-10-11 14:29:11 +0200 (Thu, 11 Oct 2012) $
15
 *
16
*/
17

    
18
// Include the configuration file
19
if(!defined('WB_URL') && file_exists(realpath('../../../config.php'))) {
20
	require('../../../config.php');
21
}
22
// Include the language file
23
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
24

    
25
// Include the database class file and initiate an object
26
//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
$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
$results = $results->fetchRow(MYSQL_ASSOC);
34
$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

    
39
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
40

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

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

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

    
58
		} else {
59

    
60
			$old_pass = $results_array['password'];
61

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

    
74
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
75

    
76
			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
				$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
83

    
84
				// Replace placeholders from language variable with values
85
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
86
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
87
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
88

    
89
				// Try sending the email
90
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
91
					$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
92
					$display_form = false;
93
				} else {
94
					$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
95
					$message = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
96
				}
97
			}
98

    
99
		}
100

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

    
108
} else {
109
	$email = '';
110
}
111

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

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

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

    
173
if(defined('DEFAULT_CHARSET')) {
174
	$charset=DEFAULT_CHARSET;
175
} else {
176
	$charset='utf-8';
177
}
178

    
179
$template->set_var('CHARSET', $charset);
180

    
181
$template->parse('main', 'main_block', false);
182
$template->pparse('output', 'page');
183

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