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 2052 2013-12-29 14:14:31Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
14
 * @lastmodified    $Date: 2013-12-29 15:14:31 +0100 (Sun, 29 Dec 2013) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(!defined('WB_PATH')) {
21
	require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php');
22
	throw new IllegalFileException();
23
}
24
/* -------------------------------------------------------- */
25
// Check if the user has already submitted the form, otherwise show it
26
$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
27
$errMsg ='';
28

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

    
32
if(isset($_POST['email']) && is_string($_POST['email']) )
33
{
34

    
35
    if($_POST['email'] != "" )
36
    {
37
    
38
    	$email = strip_tags($_POST['email']);
39
    	if($wb->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($email).'\'';
48

    
49
        	if(($results = $database->query($sql)))
50
        	{
51
        		if(($results_array = $results->fetchRow(MYSQL_ASSOC)))
52
        		{ // Get the id, username, email, and last_reset from the above db query
53
        		// Check if the password has been reset in the last 2 hours
54
        			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
55
        			// Tell the user that their password cannot be reset more than once per hour
56
        				$errMsg = $MESSAGE['FORGOT_PASS_ALREADY_RESET'];
57
        			} else {
58
        				$pwh = Password::getInstance();
59
        				$old_pass = $results_array['password'];
60
        			// Generate a random password then update the database with it
61
        				$new_pass = $pwh->createNew();
62
        				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '
63
        				     . 'SET `password`=\''.md5($new_pass).'\', '
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
//            	$errMsg = $MESSAGE['USERS_INVALID_EMAIL'];
100
        		if(DEBUG) {
101
        			$errMsg .= '<br />'.$database->get_error();
102
        			$errMsg .= '<br />'.$sql;
103
        		}
104
        	}
105
    	}
106
    }  else {
107
    	$email = '';
108
    }
109
    
110
} else {
111
	$email = '';
112
}
113

    
114
if( ($errMsg=='') && ($message != '')) {
115
	// $message = $MESSAGE['FORGOT_PASS_NO_DATA'];
116
	$message_color = '000000';
117
} else {
118
	$message = $errMsg;
119
	$message_color = 'ff0000';
120
}
121

    
122
$sIncludeHeadLinkCss = '';
123
if( is_readable(WB_PATH .'/account/frontend.css')) {
124
	$sIncludeHeadLinkCss .= '<link href="'.WB_URL.'/account/frontend.css"';
125
	$sIncludeHeadLinkCss .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
126
}
127

    
128
// set template file and assign module and template block
129
	$oTpl = new Template(dirname(__FILE__).'/htt','keep');
130
	$oTpl->set_file('page', 'forgot.htt');
131
	$oTpl->debug = false; // false, true
132
	$oTpl->set_block('page', 'main_block', 'main');
133

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

    
163
	//$oTpl->parse('message', 'message_block', true);
164
	$oTpl->parse('main', 'main_block', false);
165
	$output = $oTpl->finish($oTpl->parse('output', 'page'));
166
	unset($oTpl);
167
	print $output;
(9-9/22)