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: login_form.php 1546 2011-12-18 20:00:32Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/login_form.php $
14
 * @lastmodified    $Date: 2011-12-18 21:00:32 +0100 (Sun, 18 Dec 2011) $
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
if(isset($_POST['email']) && $_POST['email'] != "" &&
22
    preg_match("/([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/i", $_POST['email']))
23
{
24
	$email = strip_tags($_POST['email']);
25
// Check if the email exists in the database
26
	$sql  = 'SELECT `user_id`,`username`,`display_name`,`email`,`last_reset`,`password` '.
27
	        'FROM `'.TABLE_PREFIX.'users` '.
28
	        'WHERE `email`=\''.$wb->add_slashes($_POST['email']).'\'';
29
	if(($results = $database->query($sql)))
30
	{
31
		if(($results_array = $results->fetchRow()))
32
		{ // Get the id, username, email, and last_reset from the above db query
33
		// Check if the password has been reset in the last 2 hours
34
			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
35
			// Tell the user that their password cannot be reset more than once per hour
36
				$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
37
			} else {
38
				require_once(WB_PATH.'/framework/PasswordHash.php');
39
				$pwh = new PasswordHash(0, true);
40
				$old_pass = $results_array['password'];
41
			// Generate a random password then update the database with it
42
				$new_pass = $pwh->NewPassword();
43
				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
44
				       'SET `password`=\''.$pwh->HashPassword($new_pass, true).'\', '.
45
				           '`last_reset`='.time().' '.
46
				       'WHERE `user_id`='.(int)$results_array['user_id'];
47
				unset($pwh); // destroy $pwh-Object
48
				if($database->query($sql))
49
				{ // Setup email to send
50
					$mail_to = $email;
51
					$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
52
				// Replace placeholders from language variable with values
53
					$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
54
					$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
55
					$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
56
				// Try sending the email
57
					if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
58
						$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
59
						$display_form = false;
60
					}else { // snd mail failed, rollback
61
						$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
62
						       'SET `password`=\''.$old_pass.'\' '.
63
						       'WHERE `user_id`='.(int)$results_array['user_id'];
64
						$database->query($sql);
65
						$message = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
66
					}
67
				}else { // Error updating database
68
					$message = $MESSAGE['RECORD_MODIFIED_FAILED'];
69
					if(DEBUG) {
70
						$message .= '<br />'.$database->get_error();
71
						$message .= '<br />'.$sql;
72
					}
73
				}
74
			}
75
		}else { // no record found - Email doesn't exist, so tell the user
76
			$message = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
77
		}
78
	} else { // Query failed
79
		$message = 'SystemError:: Database query failed!';
80
		if(DEBUG) {
81
			$message .= '<br />'.$database->get_error();
82
			$message .= '<br />'.$sql;
83
		}
84
	}
85
} else {
86
	$email = '';
87
}
88

    
89
if(isset($message) && $message != '') {
90
	$message_color = 'FF0000';
91
} else {
92
	$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
93
	$message_color = '000000';
94
}
95

    
96
$_SESSION['PAGE_LINK'] = get_page_link( $_SESSION['PAGE_ID'] );
97
$_SESSION['HTTP_REFERER'] = page_link($_SESSION['PAGE_LINK']);
98
	
99
?>
100
<div style="margin: 1em auto;">
101
	<button type="button" value="cancel" onClick="javascript: window.location = '<?php print $_SESSION['HTTP_REFERER'] ?>';"><?php print $TEXT['CANCEL'] ?></button>
102
</div>
103
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
104
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post">
105
	<input type="hidden" name="url" value="{URL}" />
106
		<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
107
		<tr>
108
			<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
109
			<?php echo $message; ?>
110
			</td>
111
		</tr>
112
<?php if(!isset($display_form) OR $display_form != false) { ?>
113
		<tr>
114
			<td height="10" colspan="2"></td>
115
		</tr>
116
		<tr>
117
			<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
118
			<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
119
			<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>
120
		</tr>
121
<?php } ?>
122
		</table>
123
</form>
(8-8/16)