passreset.php 3.48 KB
Newer Older
1
2
3
4
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');

5
include_once("aur.inc.php");         # access AUR common functions
6
7
8
9
10

set_lang();                 # this sets up the visitor's language
check_sid();                # see if they're still logged in

if (isset($_COOKIE["AURSID"])) {
11
	header('Location: /');
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
	exit();
}

$error = '';

if (isset($_GET['resetkey'], $_POST['email'], $_POST['password'], $_POST['confirm'])) {
	$resetkey = $_GET['resetkey'];
	$email = $_POST['email'];
	$password = $_POST['password'];
	$confirm = $_POST['confirm'];
	$uid = uid_from_email($email);

	if (empty($email) || empty($password)) {
		$error = __('Missing a required field.');
	} elseif ($password != $confirm) {
		$error = __('Password fields do not match.');
	} elseif ($uid == NULL || $uid == 'None') {
		$error = __('Invalid e-mail.');
	}

	if (empty($error)) {
Denis's avatar
Denis committed
33
34
		$salt = generate_salt();
		$hash = salted_hash($password, $salt);
canyonknight's avatar
canyonknight committed
35
36

		$error = password_reset($hash, $salt, $resetkey, $email);
37
38
39
40
41
42
43
	}
} elseif (isset($_POST['email'])) {
	$email = $_POST['email'];
	$uid = uid_from_email($email);
	if ($uid != NULL && $uid != 'None') {
		# We (ab)use new_sid() to get a random 32 characters long string
		$resetkey = new_sid();
canyonknight's avatar
canyonknight committed
44
		create_resetkey($resetkey, $uid);
45
46
47
48
49
50
		# Send email with confirmation link
		$body = __('A password reset request was submitted for the account '.
		           'associated with your e-mail address. If you wish to reset '.
		           'your password follow the link below, otherwise ignore '.
		           'this message and nothing will happen.').
		           "\n\n".
51
			   "{$AUR_LOCATION}/" . get_uri('/passreset/') . "?".
52
53
		           "resetkey={$resetkey}";
		$body = wordwrap($body, 70);
54
55
		$headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR";
		@mail($email, 'AUR Password Reset', $body, $headers);
56
57

	}
58
	header('Location: ' . get_uri('/passreset/') . '?step=confirm');
59
60
61
62
63
64
65
66
67
	exit();
}

$step = isset($_GET['step']) ? $_GET['step'] : NULL;

html_header(__("Password Reset"));

?>

68
<div class="box">
Lukas Fleischer's avatar
Lukas Fleischer committed
69
	<h2><?= __("Password Reset"); ?></h2>
70
71

	<?php if ($error): ?>
Lukas Fleischer's avatar
Lukas Fleischer committed
72
		<p><span class="error"><?= $error ?></span></p>
73
74
75
76
77
78
79
80
81
82
83
	<?php endif;?>
	<?php
	if ($step == 'confirm') {
		echo __('Check your e-mail for the confirmation link.');
	} elseif ($step == 'complete') {
		echo __('Your password has been reset successfully.');
	} elseif (isset($_GET['resetkey'])) {
	?>
	<form action="" method="post">
		<table>
			<tr>
Lukas Fleischer's avatar
Lukas Fleischer committed
84
				<td><?= __("Confirm your e-mail address:"); ?></td>
85
86
87
				<td><input type="text" name="email" size="30" maxlength="64" /></td>
			</tr>
			<tr>
Lukas Fleischer's avatar
Lukas Fleischer committed
88
				<td><?= __("Enter your new password:"); ?></td>
89
90
91
				<td><input type="password" name="password" size="30" maxlength="32" /></td>
			</tr>
			<tr>
Lukas Fleischer's avatar
Lukas Fleischer committed
92
				<td><?= __("Confirm your new password:"); ?></td>
93
94
95
96
				<td><input type="password" name="confirm" size="30" maxlength="32" /></td>
			</tr>
		</table>
		<br />
Lukas Fleischer's avatar
Lukas Fleischer committed
97
		<input type="submit" class="button" value="<?= __('Continue') ?>" />
98
99
100
101
	</form>
	<?php
	} else {
	?>
Lukas Fleischer's avatar
Lukas Fleischer committed
102
	<p><?= __('If you have forgotten the e-mail address you used to register, please send a message to the %saur-general%s mailing list.',
103
104
105
	'<a href="http://mailman.archlinux.org/mailman/listinfo/aur-general">',
	'</a>'); ?></p>
	<form action="" method="post">
Lukas Fleischer's avatar
Lukas Fleischer committed
106
		<p><?= __("Enter your e-mail address:"); ?>
107
		<input type="text" name="email" size="30" maxlength="64" /></p>
Lukas Fleischer's avatar
Lukas Fleischer committed
108
		<input type="submit" class="button" value="<?= __('Continue') ?>" />
109
110
	</form>
	<?php } ?>
111
112
113
114
115
</div>

<?php

html_footer(AUR_VERSION);