-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot_password.php
More file actions
58 lines (53 loc) · 1.61 KB
/
forgot_password.php
File metadata and controls
58 lines (53 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require_once('./config/include.php');
require_once('./src/reset_pwd.php');
$info = $err_email = $error = '';
if (is_post_request()) {
if (empty($_POST['email'])) {
$err_email = 'Please provide your email address.';
}
else {
$email = input_data($_POST['email']);
try {
$link = create_password_reset_link($dbc, $email, $root_url);
send_password_reset_link($sender_email, $email, $link);
$qparam = http_build_query(array('info' => 'reset'));
header('Location: forgot_password.php?' . $qparam);
}
catch (NoUserFoundException $e) {
$info = 'No user found. Please try again.' . PHP_EOL;
}
catch (FailedToSendMail $e) {
$info = 'Failed to send email.' . PHP_EOL;
}
}
echo get_template('forgot_password.php', array(
'title' => 'Forgot Password',
'info' => $info,
'error' => $error,
'err_email' => $err_email,
));
}
if (is_get_request()) {
if (isset($_GET['t'])) {
$token = isset($_GET['t']) ? trim($_GET['t']) : '';
$request_data = fetch_from_password_reset_table($dbc, $token);
if (!$request_data)
$info = 'Error fetching request, try again.';
else {
session_regenerate_id();
$_SESSION['user_id_reset_pass'] = $request_data['user_id'];
$qparam = http_build_query(array('info' => 'reset'));
header('Location: reset_password.php?' . $qparam);
}
}
if (isset($_GET['info']) && $_GET['info'] === 'reset')
$info = 'Thanks, the link is sent to your email!';
echo get_template('forgot_password.php', array(
'title' => 'Forgot Password',
'info' => $info,
'error' => $error,
'err_email' => $err_email,
));
}
?>