mirror of
https://github.com/friendica/friendica
synced 2025-04-24 23:50:20 +00:00
Refactor "Authentication" class with four main methods:
- withSession() - for auto authentication with Session/Cookie variables - withOpenId() - for authentication with an OpenID account - withPassword() - for authentication with Password - setForUser() - for setting the user auth context of the current session Refactor "Session" class - contains now "native" Session Management methods
This commit is contained in:
parent
18a3d18ba6
commit
96555a7385
13 changed files with 386 additions and 301 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Authentication;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
|
@ -79,7 +80,9 @@ class Delegation extends BaseModule
|
|||
|
||||
Session::clear();
|
||||
|
||||
Session::setAuthenticatedForUser(self::getApp(), $user, true, true);
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->setForUser(self::getApp(), $user, true, true);
|
||||
|
||||
if ($limited_id) {
|
||||
Session::set('submanage', $original_id);
|
||||
|
|
|
@ -35,11 +35,8 @@ class Login extends BaseModule
|
|||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
$openid_identity = Session::get('openid_identity');
|
||||
$openid_server = Session::get('openid_server');
|
||||
|
||||
$return_path = Session::get('return_path');
|
||||
session_unset();
|
||||
Session::clear();
|
||||
Session::set('return_path', $return_path);
|
||||
|
||||
// OpenId Login
|
||||
|
@ -50,16 +47,19 @@ class Login extends BaseModule
|
|||
) {
|
||||
$openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']);
|
||||
|
||||
Authentication::openIdAuthentication($openid_url, !empty($_POST['remember']));
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->withOpenId($openid_url, !empty($_POST['remember']));
|
||||
}
|
||||
|
||||
if (!empty($_POST['auth-params']) && $_POST['auth-params'] === 'login') {
|
||||
Authentication::passwordAuthentication(
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->withPassword(
|
||||
self::getApp(),
|
||||
trim($_POST['username']),
|
||||
trim($_POST['password']),
|
||||
!empty($_POST['remember']),
|
||||
$openid_identity,
|
||||
$openid_server
|
||||
!empty($_POST['remember'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Core\Authentication;
|
|||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Profile;
|
||||
|
||||
|
@ -32,7 +33,7 @@ class Logout extends BaseModule
|
|||
}
|
||||
|
||||
Hook::callAll("logging_out");
|
||||
Authentication::deleteSession();
|
||||
Session::delete();
|
||||
|
||||
if ($visitor_home) {
|
||||
System::externalRedirect($visitor_home);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Friendica\Module\TwoFactor;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Authentication;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
|
@ -41,7 +42,9 @@ class Recovery extends BaseModule
|
|||
notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user())));
|
||||
|
||||
// Resume normal login workflow
|
||||
Session::setAuthenticatedForUser($a, $a->user, true, true);
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->setForUser($a, $a->user, true, true);
|
||||
} else {
|
||||
notice(L10n::t('Invalid code, please retry.'));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Friendica\Module\TwoFactor;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Authentication;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Renderer;
|
||||
|
@ -38,7 +39,9 @@ class Verify extends BaseModule
|
|||
Session::set('2fa', $code);
|
||||
|
||||
// Resume normal login workflow
|
||||
Session::setAuthenticatedForUser($a, $a->user, true, true);
|
||||
/** @var Authentication $authentication */
|
||||
$authentication = self::getClass(Authentication::class);
|
||||
$authentication->setForUser($a, $a->user, true, true);
|
||||
} else {
|
||||
self::$errors[] = L10n::t('Invalid code, please retry.');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue