Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         login
6
 * @author          Ryan Djurovich (2004-2009), 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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
15
 *
16
*/
17

    
18
// Include the configuration file
19
$config_file = realpath('../../../config.php');
20
if(file_exists($config_file) && !defined('WB_URL'))
21
{
22
	require_once($config_file);
23
}
24
$oDb = WbDatabase::getInstance();
25
$oTrans = Translate::getInstance();
26
$admin = new admin('Start', 'start', false, false);
27
// Check if the user has already submitted the form, otherwise show it
28
if(isset($_POST['email']) && is_string($_POST['email']) && $_POST['email'] != "") {
29
	$email = htmlspecialchars($_POST['email'],ENT_QUOTES);
30
	// Check if the email exists in the database
31
	$sql = 'SELECT `user_id`, `username`, `display_name`, `email`, `last_reset`, `password` '
32
         . 'FROM `'.$oDb->TablePrefix.'users` '
33
         . 'WHERE `email`=\''.$admin->add_slashes($_POST['email']).'\'';
34
	$results = $oDb->doQuery($sql);
35
    if (($results_array = $results->fetchRow(MYSQL_ASSOC))) {
36
		// Get the id, username, email, and last_reset from the above db query
37
		// Check if the password has been reset in the last 2 hours
38
		$last_reset = $results_array['last_reset'];
39
		$time_diff = (time()-$last_reset) / (60 * 60); // Time since last reset in hours
40
		if($time_diff < 2) {
41
			// Tell the user that their password cannot be reset more than once per hour
42
			$message = $oTrans->MESSAGE_FORGOT_PASS_ALREADY_RESET;
43
		} else {
44
			$old_pass = $results_array['password'];
45
			// Generate a random password then update the database with it
46
            $oPassword = new Password();
47
            $new_pass = $oPassword->createNew(8, Password::PW_USE_ALL);
48
			$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
49
                 . 'SET `password`=\''.md5($new_pass).'\', '
50
                 .     '`last_reset`='.time().' '
51
                 . 'WHERE `user_id`='.(int)$results_array['user_id'];
52
			if ($oDb->doQuery($sql)) {
53
				// Setup email to send
54
				$mail_to = $email;
55
				$mail_subject = $oTrans->MESSAGE_SIGNUP2_SUBJECT_LOGIN_INFO;
56
				// Replace placeholders from language variable with values
57
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
58
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
59
				$mail_message = str_replace($search, $replace, $oTrans->MESSAGE_SIGNUP2_BODY_LOGIN_FORGOT);
60
				// Try sending the email
61
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
62
					$message = $oTrans->MESSAGE_FORGOT_PASS_PASSWORD_RESET;
63
					$display_form = false;
64
				} else {
65
					$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
66
                         . 'SET `password`=\''.$old_pass.'\' '
67
                         . 'WHERE `user_id`='.(int)$results_array['user_id'];
68
					$oDb->doQuery($sql);
69
					$message = $oTrans->MESSAGE_FORGOT_PASS_CANNOT_EMAIL;
70
				}
71
			} else {
72
				// Error updating database
73
				$message = $oDb->getError();
74
            }
75
		}
76
	} else {
77
		// Email doesn't exist, so tell the user
78
		$message = $oTrans->MESSAGE_FORGOT_PASS_EMAIL_NOT_FOUND;
79
		// and delete the wrong Email
80
		$email = '';
81
	}
82
} else {
83
	$email = '';
84
}
85
if(!isset($message)) {
86
	$message = $oTrans->MESSAGE_FORGOT_PASS_NO_DATA;
87
	$message_color = '000000';
88
} else {
89
	$message_color = 'FF0000';
90
}
91

    
92
// Setup template object, parse vars to it, then parse it
93
// Create new template object
94
$template = new Template(dirname($admin->correct_theme_source('loginForgot.htt')));
95
$template->set_file('page', 'loginForgot.htt');
96
$template->set_block('page', 'main_block', 'main');
97
if(defined('FRONTEND')) {
98
	$template->set_var('ACTION_URL', 'forgot.php');
99
} else {
100
	$template->set_var('ACTION_URL', 'index.php');
101
}
102
$template->set_var('EMAIL', $email);
103
$template->set_var($oTrans->getLangArray());
104
if(isset($display_form)) {
105
	$template->set_var('DISPLAY_FORM', 'display:none;');
106
}
107
$template->set_var(array(
108
        'SECTION_FORGOT'       => $oTrans->MENU_FORGOT,
109
        'MESSAGE_COLOR'        => $message_color,
110
        'MESSAGE'              => $message,
111
        'WEBSITE_TITLE'        => WEBSITE_TITLE,
112
        'ADMIN_URL'            => ADMIN_URL,
113
        'WB_URL'               => WB_URL,
114
        'URL_VIEW'             => WB_URL,
115
        'THEME_URL'            => THEME_URL,
116
        'VERSION'              => VERSION,
117
        'SP'                   => (defined('SP') ? SP : ''),
118
        'REVISION'             => REVISION,
119
        'LANGUAGE'             => strtolower(LANGUAGE),
120
        'LOGIN_ICON'           => 'login',
121
        'LOGIN_LINK'           => $_SERVER['SCRIPT_NAME'],
122
        'START_ICON'           => 'blank',
123
        'LOGIN_DISPLAY_HIDDEN' => !$admin->is_authenticated() ? 'hidden' : '',
124
        'LOGIN_DISPLAY_NONE'   => !$admin->is_authenticated() ? 'none' : '',
125
        'URL_HELP'             => 'http://www.websitebaker.org/',
126
        'URL'                  => ADMIN_URL."/start/index.php"
127
    )
128
);
129

    
130
if(defined('FRONTEND')) {
131
	$template->set_var('LOGIN_URL', WB_URL.'/account/login.php');
132
} else {
133
	$template->set_var('LOGIN_URL', ADMIN_URL);
134
}
135
$template->set_var('INTERFACE_URL', ADMIN_URL.'/interface');
136

    
137
if(defined('DEFAULT_CHARSET')) {
138
	$charset=DEFAULT_CHARSET;
139
} else {
140
	$charset='utf-8';
141
}
142

    
143
$template->set_var('CHARSET', $charset);
144

    
145
$template->parse('main', 'main_block', false);
146
$template->pparse('output', 'page');
147

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