Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         login
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id: index.php 1289 2010-02-10 15:13:21Z kweitzel $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/trunk/wb/admin/login/forgot/index.php $
15
 * @lastmodified    $Date: 2010-02-10 16:13:21 +0100 (Wed, 10 Feb 2010) $
16
 *
17
*/
18

    
19
// Include the configuration file
20
require('../../../config.php');
21
// Include the language file
22
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
23
// Include the database class file and initiate an object
24
require(WB_PATH.'/framework/class.admin.php');
25
$admin = new admin('Start', 'start', false, false);
26
$database = new database();
27

    
28
// Get the website title
29
$results = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
30
$results = $results->fetchRow();
31
$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
	
36
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
37
	
38
	// 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
		$results_array = $results->fetchRow();
45
		
46
		// 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
			
52
			// Tell the user that their password cannot be reset more than once per hour
53
			$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
54
			
55
		} else {
56
			
57
			$old_pass = $results_array['password'];
58
			
59
			// 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
			
71
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
72
			
73
			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
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); 
84
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
85

    
86
				// Try sending the email
87
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { 
88
					$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
		
96
		}
97
		
98
	} 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
	
105
} 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
	
116
// Setup the template
117
$template = new Template(THEME_PATH.'/templates');
118
$template->set_file('page', 'login_forgot.htt');
119
$template->set_block('page', 'main_block', 'main');
120
if(defined('FRONTEND')) {
121
	$template->set_var('ACTION_URL', 'forgot.php');
122
} else {
123
	$template->set_var('ACTION_URL', 'index.php');
124
}
125
$template->set_var('EMAIL', $email);
126

    
127
if(isset($display_form)) {
128
	$template->set_var('DISPLAY_FORM', 'display:none;');
129
}
130

    
131
$template->set_var(array(
132
								'SECTION_FORGOT' => $MENU['FORGOT'],
133
								'MESSAGE_COLOR' => $message_color,
134
								'MESSAGE' => $message,
135
								'WB_URL' => WB_URL,
136
								'ADMIN_URL' => ADMIN_URL,
137
								'THEME_URL' => THEME_URL,
138
								'LANGUAGE' => strtolower(LANGUAGE),
139
								'TEXT_EMAIL' => $TEXT['EMAIL'],
140
								'TEXT_SEND_DETAILS' => $TEXT['SEND_DETAILS'],
141
								'TEXT_HOME' => $TEXT['HOME'],
142
								'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN']
143
								)
144
						);
145

    
146
if(defined('FRONTEND')) {
147
	$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
148
} else {
149
	$template->set_var('LOGIN_URL', ADMIN_URL);
150
}
151
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');	
152

    
153
if(defined('DEFAULT_CHARSET')) {
154
	$charset=DEFAULT_CHARSET;
155
} else {
156
	$charset='utf-8';
157
}
158

    
159
$template->set_var('CHARSET', $charset);	
160

    
161
$template->parse('main', 'main_block', false);
162
$template->pparse('output', 'page');
163

    
164
?>
    (1-1/1)