-
Notifications
You must be signed in to change notification settings - Fork 2
/
recovery.php
64 lines (56 loc) · 2.73 KB
/
recovery.php
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
59
60
61
62
63
64
<?php
require_once('core/Main.php');
$status = NULL;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_ENCODED);
$username = strtolower($username);
$status = 'RESET_PASSWORD';
if (!$userSystem->usernameExists($username)) {
$status = 'USER_DOES_NOT_EXIST';
$log->warning('recovery.php', 'Tried to reset passwort for non-existent user name: ' . $username);
}
if ($status == 'RESET_PASSWORD') {
$user = $userSystem->resetPasswordAndSendMail($username);
if ($user != NULL) {
$log->setUsername($username);
$log->info('recovery.php', 'Passwort reset and mail sent successfully for user ' . $username);
$redirect->redirectTo('login.php');
} else {
$log->setUsername($username);
$log->error('recovery.php', 'Passwort reset and mail sent not successfully for user ' . $username);
}
}
}
echo $header->getHeader($i18n->get('title'), $i18n->get('resetPassword'), array('login.css'));
function getResetPasswordField($message, $success, $i18n) {
$color = '';
if (!$success) {
$color = ' style="background-color: red;"';
}
return '<div id="loginField">
<br>
<img src="static/img/ppiLogo.png' . $GLOBALS["VERSION_STRING"] . '" id="ppiLogo" alt="ppi logo">
<br>
<br>
<div id="infoText">' . $message . '</div>
<form method="POST" action="">
<input type="text" id="username" name="username" placeholder="' . $i18n->get('userZxShort') . '"' . $color . ' maxlength="7" required>
<input type="submit" id="login" value="' . $i18n->get('resetPassword') . '">
</form>
<br>
<br>
<div id="leftRightLink">
<a href="login.php" id="leftLink">' . $i18n->get('backToLogin') . '</a>
<a href="create.php" id="rightLink">' . $i18n->get('createAccount') . '</a>
</div>
<br>
</div>';
}
if ($status == NULL) {
echo getResetPasswordField($i18n->get('resetPasswordMessage'), true, $i18n);
} else if ($status == 'RESET_PASSWORD') {
echo getResetPasswordField($i18n->get('resetPasswordSuccessfulMessage'), true, $i18n);
} else if ($status == 'USER_DOES_NOT_EXIST') {
echo getResetPasswordField($i18n->get('userDoesNotExist'), false, $i18n);
}
echo $footer->getFooter();