Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker 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 1599 2012-02-06 15:59:24Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
14
 * @lastmodified    $Date: 2012-02-06 16:59:24 +0100 (Mon, 06 Feb 2012) $
15
 *
16
 */
17

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

    
96
if( ($errMsg=='') && ($message != '')) {
97
	// $message = $MESSAGE['FORGOT_PASS_NO_DATA'];
98
	$message_color = '000000';
99
} else {
100
	$message = $errMsg;
101
	$message_color = 'ff0000';
102
}
103
?>
104
<div style="margin: 1em auto;">
105
	<button type="button" value="cancel" onClick="javascript: window.location = '<?php print $_SESSION['HTTP_REFERER'] ?>';"><?php print $TEXT['CANCEL'] ?></button>
106
</div>
107
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
108
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post">
109
	<input type="hidden" name="url" value="{URL}" />
110
		<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
111
		<tr>
112
			<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
113
			<strong><?php echo $message; ?></strong>
114
			</td>
115
		</tr>
116
<?php if(!isset($display_form) OR $display_form != false) { ?>
117
		<tr>
118
			<td height="10" colspan="2"></td>
119
		</tr>
120
		<tr>
121
			<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
122
			<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
123
			<td><input type="submit" name="submit" value="<?php echo $TEXT['SEND_DETAILS']; ?>" style="width: 180px; font-size: 10px; color: #003366; border: 1px solid #336699; background-color: #DDDDDD; padding: 3px; text-transform: uppercase;" /></td>
124
		</tr>
125
<?php } ?>
126
		</table>
127
</form>
(4-4/16)