Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         login
6
 * @author          Ryan Djurovich, 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 1709 2012-08-29 11:37:46Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2012-08-29 13:37:46 +0200 (Wed, 29 Aug 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
// Include the database class file and initiate an object
25
require(WB_PATH.'/framework/class.admin.php');
26
$admin = new admin('Start', 'start', false, false);
27

    
28
// Get the website title
29
$results = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
30
$results = $results->fetchRow(MYSQL_ASSOC);
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(MYSQL_ASSOC);
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_FORGOT']);
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 template object, parse vars to it, then parse it
117
// Create new template object
118
$template = new Template(dirname($admin->correct_theme_source('loginForgot.htt')));
119
$template->set_file('page', 'loginForgot.htt');
120
$template->set_block('page', 'main_block', 'main');
121
if(defined('FRONTEND')) {
122
	$template->set_var('ACTION_URL', 'forgot.php');
123
} else {
124
	$template->set_var('ACTION_URL', 'index.php');
125
}
126
$template->set_var('EMAIL', $email);
127

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

    
132
$template->set_var(array(
133
				'SECTION_FORGOT' => $MENU['FORGOT'],
134
				'MESSAGE_COLOR' => $message_color,
135
				'MESSAGE' => $message,
136
				'WEBSITE_TITLE' => WEBSITE_TITLE,
137
				'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
138
				'ADMIN_URL' => ADMIN_URL,
139
				'WB_URL' => WB_URL,
140
				'URL_VIEW' => WB_URL,
141
				'THEME_URL' => THEME_URL,
142
				'VERSION' => VERSION,
143
				'SP' => (defined('SP') ? SP : ''),
144
				'REVISION' => REVISION,
145
				'LANGUAGE' => strtolower(LANGUAGE),
146
				'TEXT_EMAIL' => $TEXT['EMAIL'],
147
				'TEXT_SEND_DETAILS' => $TEXT['SEND_DETAILS'],
148
				'TEXT_LOGIN' => $TEXT['LOGIN'],
149
				'TITLE_LOGOUT' => $MENU['LOGIN'],
150
				'TEXT_RESET' => $TEXT['RESET'],
151
				'TEXT_HOME' => $TEXT['HOME'],
152
				'TITLE_VIEW' => $TEXT['WEBSITE'],
153
				'LOGIN_ICON' => 'login',
154
				'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
155
				'START_ICON' => 'blank',
156
				'LOGIN_DISPLAY_HIDDEN' => !$admin->is_authenticated() ? 'hidden' : '',
157
				'LOGIN_DISPLAY_NONE' => !$admin->is_authenticated() ? 'none' : '',
158
				'URL_HELP' => 'http://www.websitebaker.org/',
159
				'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN']
160
				)
161
		);
162

    
163
if(defined('FRONTEND')) {
164
	$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
165
} else {
166
	$template->set_var('LOGIN_URL', ADMIN_URL);
167
}
168
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');
169

    
170
if(defined('DEFAULT_CHARSET')) {
171
	$charset=DEFAULT_CHARSET;
172
} else {
173
	$charset='utf-8';
174
}
175

    
176
$template->set_var('CHARSET', $charset);
177

    
178
$template->parse('main', 'main_block', false);
179
$template->pparse('output', 'page');
180

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