mirror of
https://github.com/friendica/friendica
synced 2025-04-22 13:50:12 +00:00
Move Login/Logout/TwoFactor to bundled submodule "Security"
This commit is contained in:
parent
d30e8665e1
commit
aa5771cf3e
27 changed files with 31 additions and 26 deletions
75
src/Module/Security/TwoFactor/Recovery.php
Normal file
75
src/Module/Security/TwoFactor/Recovery.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Security\TwoFactor;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\App\Authentication;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Model\TwoFactor\RecoveryCode;
|
||||
|
||||
/**
|
||||
* // Page 1a: Recovery code verification
|
||||
*
|
||||
* @package Friendica\Module\TwoFactor
|
||||
*/
|
||||
class Recovery extends BaseModule
|
||||
{
|
||||
public static function init(array $parameters = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($_POST['action'] ?? '') == 'recover') {
|
||||
self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_recovery');
|
||||
|
||||
$a = self::getApp();
|
||||
|
||||
$recovery_code = $_POST['recovery_code'] ?? '';
|
||||
|
||||
if (RecoveryCode::existsForUser(local_user(), $recovery_code)) {
|
||||
RecoveryCode::markUsedForUser(local_user(), $recovery_code);
|
||||
Session::set('2fa', true);
|
||||
notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user())));
|
||||
|
||||
// Resume normal login workflow
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->setForUser($a, $a->user, true, true);
|
||||
} else {
|
||||
notice(L10n::t('Invalid code, please retry.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
self::getApp()->internalRedirect();
|
||||
}
|
||||
|
||||
// Already authenticated with 2FA token
|
||||
if (Session::get('2fa')) {
|
||||
self::getApp()->internalRedirect();
|
||||
}
|
||||
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/recovery.tpl'), [
|
||||
'$form_security_token' => self::getFormSecurityToken('twofactor_recovery'),
|
||||
|
||||
'$title' => L10n::t('Two-factor recovery'),
|
||||
'$message' => L10n::t('<p>You can enter one of your one-time recovery codes in case you lost access to your mobile device.</p>'),
|
||||
'$recovery_message' => L10n::t('Don’t have your phone? <a href="%s">Enter a two-factor recovery code</a>', '2fa/recovery'),
|
||||
'$recovery_code' => ['recovery_code', L10n::t('Please enter a recovery code'), '', '', '', 'placeholder="000000-000000"'],
|
||||
'$recovery_label' => L10n::t('Submit recovery code and complete login'),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue