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 2119 2014-12-28 21:44:13Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/login/forgot/index.php $
14
 * @lastmodified    $Date: 2014-12-28 22:44:13 +0100 (Sun, 28 Dec 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
            $new_pass = Password::createNew(10, Password::PW_USE_ALL);
47
			$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
48
                 . 'SET `password`=\''.md5($new_pass).'\', '
49
                 .     '`last_reset`='.time().' '
50
                 . 'WHERE `user_id`='.(int)$results_array['user_id'];
51
			if ($oDb->doQuery($sql)) {
52
				// Setup email to send
53
				$mail_to = $email;
54
				$mail_subject = $oTrans->MESSAGE_SIGNUP2_SUBJECT_LOGIN_INFO;
55
				// Replace placeholders from language variable with values
56
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
57
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
58
				$mail_message = str_replace($search, $replace, $oTrans->MESSAGE_SIGNUP2_BODY_LOGIN_FORGOT);
59
				// Try sending the email
60
				if($admin->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
61
					$message = $oTrans->MESSAGE_FORGOT_PASS_PASSWORD_RESET;
62
					$display_form = false;
63
				} else {
64
					$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
65
                         . 'SET `password`=\''.$old_pass.'\' '
66
                         . 'WHERE `user_id`='.(int)$results_array['user_id'];
67
					$oDb->doQuery($sql);
68
					$message = $oTrans->MESSAGE_FORGOT_PASS_CANNOT_EMAIL;
69
				}
70
			} else {
71
				// Error updating database
72
				$message = $oDb->getError();
73
            }
74
		}
75
	} else {
76
		// Email doesn't exist, so tell the user
77
		$message = $oTrans->MESSAGE_FORGOT_PASS_EMAIL_NOT_FOUND;
78
		// and delete the wrong Email
79
		$email = '';
80
	}
81
} else {
82
	$email = '';
83
}
84
if(!isset($message)) {
85
	$message = $oTrans->MESSAGE_FORGOT_PASS_NO_DATA;
86
	$message_color = '000000';
87
} else {
88
	$message_color = 'FF0000';
89
}
90

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

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

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

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

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

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