Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         login
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker 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 1529 2011-11-25 05:03:32Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2011-11-25 06:03:32 +0100 (Fri, 25 Nov 2011) $
15
 *
16
*/
17

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

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

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

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

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

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

    
107
if(!isset($message)) {
108
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
109
	$message_color = '000000';
110
} else {
111
	$message_color = 'FF0000';
112
}
113
	
114
// Setup template object, parse vars to it, then parse it
115
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('login_forgot.htt'));
116
// Create new template object
117
$template = new Template($ThemePath);
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');
    (1-1/1)