Project

General

Profile

1
<?php
2

    
3
// $Id: index.php 218 2005-11-14 09:47:57Z ryan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
// Include the configuration file
27
require('../../../config.php');
28
// Include the language file
29
require(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
30
// Include the database class file and initiate an object
31
require(WB_PATH.'/framework/class.admin.php');
32
$database = new database();
33

    
34
// Get the website title
35
$results = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
36
$results = $results->fetchRow();
37
$website_title = $results['value'];
38

    
39
// Check if the user has already submitted the form, otherwise show it
40
if(isset($_POST['email']) AND $_POST['email'] != "") {
41
	
42
	$email = $_POST['email'];
43
	
44
	// Check if the email exists in the database
45
	$query = "SELECT user_id,username,display_name,email,last_reset 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();
51
		
52
		// Check if the password has been reset in the last 2 hours
53
		$last_reset = $results_array['last_reset'];
54
		$time_diff = mktime()-$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
			// Generate a random password then update the database with it
64
			$new_pass = '';
65
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
66
			srand((double)microtime()*1000000);
67
			$i = 0;
68
			while ($i <= 7) {
69
				$num = rand() % 33;
70
				$tmp = substr($salt, $num, 1);
71
				$new_pass = $new_pass . $tmp;
72
				$i++;
73
			}
74
			
75
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".mktime()."' WHERE user_id = '".$results_array['user_id']."'");
76
			
77
			if($database->is_error()) {
78
				// Error updating database
79
				$message = $database->get_error();
80
			} else {
81
				// Setup email to send
82
				$mail_subject = 'Your login details...';
83
				$mail_to = $email;
84
				$mail_message = ''.
85
	'Hello '.$results_array["display_name"].', 
86
	
87
	Your '.$website_title.' administration login details are:
88
	Username: '.$results_array["username"].'
89
	Password: '.$new_pass.'
90
	
91
	Your password has been reset to the one above.
92
	This means that your old password will no longer work.
93
	
94
	If you have received this message in error, please delete it immediatly.';
95
				// Try sending the email
96
				if(mail($mail_to, $mail_subject, $mail_message, 'From: '.SERVER_EMAIL)) {
97
					$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
98
					$display_form = false;
99
				} else {
100
					$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
101
				}
102
			}
103
		
104
		}
105
		
106
	} else {
107
		// Email doesn't exist, so tell the user
108
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
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 the template
123
$template = new Template(ADMIN_PATH.'/login/forgot');
124
$template->set_file('page', 'template.html');
125
$template->set_block('page', 'main_block', 'main');
126
if(defined('FRONTEND')) {
127
	$template->set_var('ACTION_URL', 'forgot.php');
128
} else {
129
	$template->set_var('ACTION_URL', 'index.php');
130
}
131
$template->set_var('EMAIL', $email);
132

    
133
if(isset($display_form)) {
134
	$template->set_var('DISPLAY_FORM', 'none');
135
}
136

    
137
$template->set_var(array(
138
								'SECTION_FORGOT' => $MENU['FORGOT'],
139
								'MESSAGE_COLOR' => $message_color,
140
								'MESSAGE' => $message,
141
								'WB_URL' => WB_URL,
142
								'ADMIN_URL' => ADMIN_URL,
143
								'TEXT_EMAIL' => $TEXT['EMAIL'],
144
								'TEXT_SEND_DETAILS' => $TEXT['SEND_DETAILS'],
145
								'TEXT_HOME' => $TEXT['HOME'],
146
								'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN']
147
								)
148
						);
149

    
150
if(defined('FRONTEND')) {
151
	$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
152
} else {
153
	$template->set_var('LOGIN_URL', ADMIN_URL);
154
}
155
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');	
156

    
157
$template->parse('main', 'main_block', false);
158
$template->pparse('output', 'page');
159

    
160
?>
(1-1/2)