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 1792 2012-10-24 00:43:00Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
14
 * @lastmodified    $Date: 2012-10-24 02:43:00 +0200 (Wed, 24 Oct 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
$redirect = (isset($redirect_url) && ($redirect_url!='')  ? '?redirect='.$redirect_url : '' );
32

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

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

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

    
117
$sIncludeHeadLinkCss = '';
118
if( is_readable(WB_PATH .'/account/frontend.css')) {
119
	$sIncludeHeadLinkCss .= '<link href="'.WB_URL.'/account/frontend.css"';
120
	$sIncludeHeadLinkCss .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
121
}
122

    
123
// set template file and assign module and template block
124
	$oTpl = new Template(dirname(__FILE__).'/htt','keep');
125
	$oTpl->set_file('page', 'forgot.htt');
126
	$oTpl->debug = false; // false, true
127
	$oTpl->set_block('page', 'main_block', 'main');
128

    
129
	$oTpl->set_block('main_block', 'message_block', 'message');
130
	$oTpl->set_block('message', '');
131
	if(!isset($display_form) OR $display_form != false) {}
132
// generell vars
133
	$oTpl->set_var(array(
134
		'FTAN' => $wb->getFTAN(),
135
		'ACTION_URL' => WB_URL.'/account/forgot.php',
136
		'LOGIN_URL' => WB_URL.'/account/login.php'.$redirect,
137
		'REDIRECT_URL' => $redirect_url,
138
		'URL' => $redirect_url,
139
		'WB_URL' => WB_URL,
140
		'THEME_URL' => THEME_URL,
141
		'TEMPLATE_URL' => TEMPLATE_DIR,
142
        'CSS_BLOCK'	=> $sIncludeHeadLinkCss,
143
		'HTTP_REFERER' => $_SESSION['HTTP_REFERER'],
144
		'MESSAGE_VALUE' => '',
145
		'ERROR_VALUE' => '',
146
		'THISAPP_MESSAGE_VALUE' => $message,
147
		'TEXT_USERNAME' => $TEXT['USERNAME'],
148
		'TEXT_EMAIL' => $TEXT['EMAIL'],
149
//		'USER_FIELDNAME' => $username_fieldname,
150
		'TEXT_SEND_DETAILS' => $TEXT['NEW_PASSWORD'],
151
		'TEXT_NEED_TO_LOGIN' => $TEXT['NEED_TO_LOGIN'],
152
		'MENU_FORGOT' => $MENU['FORGOT'],
153
		'TEXT_RESET' => $TEXT['RESET'],
154
		'TEXT_CANCEL' => $TEXT['CANCEL'],
155
		)
156
	);
157

    
158
	//$oTpl->parse('message', 'message_block', true);
159
	$oTpl->parse('main', 'main_block', false);
160
	$output = $oTpl->finish($oTpl->parse('output', 'page'));
161
	unset($oTpl);
162
	print $output;
(9-9/22)