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-2011, 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 5.2.2 and higher
13
 * @version         $Id: index.php 1425 2011-02-03 23:16:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
15
 * @lastmodified    $Date: 2011-02-04 00:16:12 +0100 (Fri, 04 Feb 2011) $
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

    
27
// Get the website title
28
$results = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
29
$results = $results->fetchRow();
30
$website_title = $results['value'];
31

    
32
// Check if the user has already submitted the form, otherwise show it
33
if(isset($_POST['email']) AND $_POST['email'] != "") {
34
	
35
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
36
	
37
	// Check if the email exists in the database
38
	$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'";
39
	$results = $database->query($query);
40
	if($results->numRows() > 0) {
41

    
42
		// Get the id, username, email, and last_reset from the above db query
43
		$results_array = $results->fetchRow();
44
		
45
		// Check if the password has been reset in the last 2 hours
46
		$last_reset = $results_array['last_reset'];
47
		$time_diff = time()-$last_reset; // Time since last reset in seconds
48
		$time_diff = $time_diff/60/60; // Time since last reset in hours
49
		if($time_diff < 2) {
50
			
51
			// Tell the user that their password cannot be reset more than once per hour
52
			$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
53
			
54
		} else {
55
			
56
			$old_pass = $results_array['password'];
57
			
58
			// Generate a random password then update the database with it
59
			$new_pass = '';
60
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
61
			srand((double)microtime()*1000000);
62
			$i = 0;
63
			while ($i <= 7) {
64
				$num = rand() % 33;
65
				$tmp = substr($salt, $num, 1);
66
				$new_pass = $new_pass . $tmp;
67
				$i++;
68
			}
69
			
70
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
71
			
72
			if($database->is_error()) {
73
				// Error updating database
74
				$message = $database->get_error();
75
			} else {
76
				// Setup email to send
77
				$mail_to = $email;
78
				$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
79

    
80
				// Replace placeholders from language variable with values
81
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
82
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); 
83
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_FORGOT']);
84

    
85
				// Try sending the email
86
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { 
87
					$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
88
					$display_form = false;
89
				} else {
90
					$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
91
					$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
92
				}
93
			}
94
		
95
		}
96
		
97
	} else {
98
		// Email doesn't exist, so tell the user
99
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
100
		// and delete the wrong Email
101
		$email = '';
102
	}
103
	
104
} else {
105
	$email = '';
106
}
107

    
108
if(!isset($message)) {
109
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
110
	$message_color = '000000';
111
} else {
112
	$message_color = 'FF0000';
113
}
114
	
115
// Setup the template
116
$template = new Template(THEME_PATH.'/templates');
117
$template->set_file('page', 'login_forgot.htt');
118
$template->set_block('page', 'main_block', 'main');
119
if(defined('FRONTEND')) {
120
	$template->set_var('ACTION_URL', 'forgot.php');
121
} else {
122
	$template->set_var('ACTION_URL', 'index.php');
123
}
124
$template->set_var('EMAIL', $email);
125

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

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

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

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

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

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

    
163
?>
    (1-1/1)