mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Fix pw recovery without totp (#1032)
Check if user has TOTP active, if so display input field in pw-change form and evaluate it.
This commit is contained in:
1 parent
f77f079d37
commit
1024befd39
3 files changed
+47
-17
No files matched your search
@@ -46,7 +46,7 @@ if (isset($_GET["abort"]) && $_GET["abort"] == "1" && authentication_mfa_incompl
|
||||
$CONF = Config::getInstance()->getAll();
|
||||
$smarty = PFASmarty::getInstance();
|
||||
$smarty->configureTheme('../');
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
|
||||
CsrfToken::assertValid(safepost('CSRF_Token'));
|
||||
|
||||
@@ -75,21 +75,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (!$handler->checkPasswordRecoveryCode($tUsername, $tCode)) {
|
||||
flash_error(Config::lang('pPassword_code_text_error'));
|
||||
} else {
|
||||
init_session($tUsername, $context === 'admin');
|
||||
if (!$handler->init($tUsername)) {
|
||||
flash_error($handler->errormsg);
|
||||
} else {
|
||||
$values = $handler->result;
|
||||
$values['password'] = $fPassword;
|
||||
$values['password2'] = $fPassword2;
|
||||
if ($handler->set($values) && $handler->save()) {
|
||||
flash_info(Config::lang_f('pPassword_result_success', $tUsername));
|
||||
$handler->wipePasswordRecoveryCode($tUsername); // so we only wipe the recovery token if they've managed to change their password.
|
||||
header('Location: main.php');
|
||||
exit(0);
|
||||
$totppf = new TotpPf($context === 'admin' ? 'admin' : 'mailbox', new Login($context === 'admin' ? 'admin' : 'mailbox'));
|
||||
|
||||
if ($totppf->usesTOTP($tUsername)) {
|
||||
$fTotp = safepost('fTOTP_code');
|
||||
|
||||
if (!$totppf->checkUserTOTP($tUsername, $fTotp)) {
|
||||
flash_error(Config::lang('pTotp_failed'));
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
init_session($tUsername, $context === 'admin', true);
|
||||
|
||||
if (!$handler->init($tUsername)) {
|
||||
flash_error($handler->errormsg);
|
||||
} else {
|
||||
foreach ($handler->errormsg as $msg) {
|
||||
flash_error($msg);
|
||||
$values = $handler->result;
|
||||
$values['password'] = $fPassword;
|
||||
$values['password2'] = $fPassword2;
|
||||
|
||||
if ($handler->set($values) && $handler->save()) {
|
||||
flash_info(Config::lang_f('pPassword_result_success', $tUsername));
|
||||
$handler->wipePasswordRecoveryCode($tUsername);
|
||||
header('Location: main.php');
|
||||
exit(0);
|
||||
} else {
|
||||
foreach ($handler->errormsg as $msg) {
|
||||
flash_error($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +112,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
$totppf = new TotpPf($context === 'admin' ? 'admin' : 'mailbox', new Login($context === 'admin' ? 'admin' : 'mailbox'));
|
||||
$tTotpRequired = $totppf->usesTOTP($tUsername);
|
||||
$smarty->assign('tTotpRequired', $tTotpRequired);
|
||||
$smarty->assign('language_selector', language_selector(), false);
|
||||
$smarty->assign('tUsername', $tUsername);
|
||||
$smarty->assign('tCode', $tCode);
|
||||
|
||||
@@ -27,7 +27,19 @@
|
||||
<input class="form-control" type="password" name="fPassword2" autocomplete="new-password"/>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit" name="submit"
|
||||
value="submit">{$PALANG.change_password}</button>
|
||||
|
||||
{if $tTotpRequired}
|
||||
<div class="form-group">
|
||||
<label for="fTOTP_code">
|
||||
{$PALANG.pTOTP_confirm}:
|
||||
</label>
|
||||
<input class="flat" type="text" name="fTOTP_code" autocomplete="one-time-code" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button class="btn btn-primary" type="submit" name="submit"
|
||||
value="submit">{$PALANG.change_password}</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user