Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          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: forgot_form.php 1728 2012-08-30 14:21:31Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
14
 * @lastmodified    $Date: 2012-08-30 16:21:31 +0200 (Thu, 30 Aug 2012) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24
}
25
/* -------------------------------------------------------- */
26
// Check if the user has already submitted the form, otherwise show it
27
$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
28
$errMsg ='';
29

    
30
$redirect_url = (isset($redirect_url) && ($redirect_url!='')  ? $redirect_url : $_SESSION['HTTP_REFERER'] );
31

    
32
//print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
33
//print_r( $redirect_url ); print '</pre>';
34

    
35
if(isset($_POST['email']) && $_POST['email'] != "" )
36
{
37
	$email = strip_tags($_POST['email']);
38
	if($admin->validate_email($email) == false)
39
    {
40
		$errMsg = $MESSAGE['USERS_INVALID_EMAIL'];
41
		$email = '';
42
	} else {
43
// Check if the email exists in the database
44
	$sql  = 'SELECT `user_id`,`username`,`display_name`,`email`,`last_reset`,`password` '.
45
	        'FROM `'.TABLE_PREFIX.'users` '.
46
	        'WHERE `email`=\''.$wb->add_slashes($_POST['email']).'\'';
47
	if(($results = $database->query($sql)))
48
	{
49
		if(($results_array = $results->fetchRow()))
50
		{ // Get the id, username, email, and last_reset from the above db query
51
		// Check if the password has been reset in the last 2 hours
52
			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
53
			// Tell the user that their password cannot be reset more than once per hour
54
				$errMsg = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
55
			} else {
56
				require_once(WB_PATH.'/framework/PasswordHash.php');
57
				$pwh = new PasswordHash(0, true);
58
				$old_pass = $results_array['password'];
59
			// Generate a random password then update the database with it
60
				$new_pass = $pwh->NewPassword();
61
				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
62
				       'SET `password`=\''.$pwh->HashPassword($new_pass, true).'\', '.
63
				           '`last_reset`='.time().' '.
64
				       'WHERE `user_id`='.(int)$results_array['user_id'];
65
				unset($pwh); // destroy $pwh-Object
66
				if($database->query($sql))
67
				{ // Setup email to send
68
					$mail_to = $email;
69
					$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
70
				// Replace placeholders from language variable with values
71
					$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
72
					$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
73
					$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
74
				// Try sending the email
75
					if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
76
						$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
77
						$display_form = false;
78
					}else { // snd mail failed, rollback
79
						$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
80
						       'SET `password`=\''.$old_pass.'\' '.
81
						       'WHERE `user_id`='.(int)$results_array['user_id'];
82
						$database->query($sql);
83
						$errMsg = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
84
					}
85
				}else { // Error updating database
86
					$errMsg = $MESSAGE['RECORD_MODIFIED_FAILED'];
87
					if(DEBUG) {
88
						$message .= '<br />'.$database->get_error();
89
						$message .= '<br />'.$sql;
90
					}
91
				}
92
			}
93
		}else { // no record found - Email doesn't exist, so tell the user
94
			$errMsg = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
95
		}
96
	} else { // Query failed
97
		$errMsg = 'SystemError:: Database query failed!';
98
		if(DEBUG) {
99
			$errMsg .= '<br />'.$database->get_error();
100
			$errMsg .= '<br />'.$sql;
101
		}
102
	}
103
	}
104
} else {
105
	$email = '';
106
}
107

    
108
if( ($errMsg=='') && ($message != '')) {
109
	// $message = $MESSAGE['FORGOT_PASS_NO_DATA'];
110
	$message_color = '000000';
111
} else {
112
	$message = $errMsg;
113
	$message_color = 'ff0000';
114
}
115

    
116
// set template file and assign module and template block
117
	$oTpl = new Template(dirname(__FILE__).'/htt','keep');
118
	$oTpl->set_file('page', 'forgot.htt');
119
	$oTpl->debug = false; // false, true
120
	$oTpl->set_block('page', 'main_block', 'main');
121

    
122
	$oTpl->set_block('main_block', 'message_block', 'message');
123
	$oTpl->set_block('message', '');
124
	if(!isset($display_form) OR $display_form != false) {}
125
// generell vars
126
	$oTpl->set_var(array(
127
		'FTAN' => $wb->getFTAN(),
128
		'ACTION_URL' => WB_URL.'/account/forgot.php',
129
		'LOGIN_URL' => WB_URL.'/account/login.php',
130
		'REDIRECT_URL' => $redirect_url,
131
		'URL' => $redirect_url,
132
		'WB_URL' => WB_URL,
133
		'THEME_URL' => THEME_URL,
134
		'HTTP_REFERER' => $_SESSION['HTTP_REFERER'],
135
		'MESSAGE_VALUE' => '',
136
		'ERROR_VALUE' => '',
137
		'THISAPP_MESSAGE_VALUE' => $message,
138
		'TEXT_USERNAME' => $TEXT['USERNAME'],
139
		'TEXT_EMAIL' => $TEXT['EMAIL'],
140
//		'USER_FIELDNAME' => $username_fieldname,
141
		'TEXT_SEND_DETAILS' => $TEXT['SEND_DETAILS'],
142
		'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN'],
143
		'MENU_FORGOT' => $MENU['FORGOT'],
144
		'TEXT_RESET' => $TEXT['RESET'],
145
		'TEXT_CANCEL' => $TEXT['CANCEL'],
146
		)
147
	);
148

    
149
	//$oTpl->parse('message', 'message_block', true);
150
	$oTpl->parse('main', 'main_block', false);
151
	$output = $oTpl->finish($oTpl->parse('output', 'page'));
152
	unset($oTpl);
153
	print $output;
(4-4/17)