1
1
Fork 0

Rebase for OpenId & Hovercard

This commit is contained in:
Philipp Holzer 2019-12-29 16:48:15 +01:00
parent 2660edbb48
commit 651d693270
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 20 additions and 37 deletions

View file

@ -9,6 +9,7 @@ use Friendica\BaseModule;
use Friendica\Core\Config\Configuration;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\HTTPException\NotFoundException;
@ -31,15 +32,12 @@ class HoverCard extends BaseModule
$nickname = $parameters['profile'];
$profile = 0;
} else {
/** @var L10n $l10n */
$l10n = self::getClass(L10n::class);
throw new NotFoundException($l10n->t('No profile'));
throw new NotFoundException(DI::l10n()->t('No profile'));
}
Profile::load($a, $nickname, $profile);
/** @var Page $page */
$page = self::getClass(Page::class);
$page = DI::page();
if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
$page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
@ -52,10 +50,8 @@ class HoverCard extends BaseModule
$page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
}
/** @var Configuration $config */
$config = self::getClass(Configuration::class);
// check if blocked
if ($config->get('system', 'block_public') && !Session::isAuthenticated()) {
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
$keywords = $a->profile['pub_keywords'] ?? '';
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
if (strlen($keywords)) {
@ -63,8 +59,7 @@ class HoverCard extends BaseModule
}
}
/** @var BaseURL $baseUrl */
$baseUrl = self::getClass(BaseURL::class);
$baseUrl = DI::baseUrl();
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));

View file

@ -9,6 +9,7 @@ use Friendica\Core\Config\Configuration;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Session\ISession;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Util\Strings;
use LightOpenID;
use Psr\Log\LoggerInterface;
@ -20,37 +21,26 @@ class OpenID extends BaseModule
{
public static function content(array $parameters = [])
{
/** @var Configuration $config */
$config = self::getClass(Configuration::class);
/** @var BaseURL $baseUrl */
$baseUrl = self::getClass(BaseURL::class);
if ($config->get('system', 'no_openid')) {
$baseUrl->redirect();
if (DI::config()->get('system', 'no_openid')) {
DI::baseUrl()->redirect();
}
/** @var LoggerInterface $logger */
$logger = self::getClass(LoggerInterface::class);
DI::logger()->debug('mod_openid.', ['request' => $_REQUEST]);
$logger->debug('mod_openid.', ['request' => $_REQUEST]);
/** @var ISession $session */
$session = self::getClass(ISession::class);
$session = DI::session();
if (!empty($_GET['openid_mode']) && !empty($session->get('openid'))) {
$openid = new LightOpenID($baseUrl->getHostname());
$openid = new LightOpenID(DI::baseUrl()->getHostname());
/** @var L10n $l10n */
$l10n = self::getClass(L10n::class);
$l10n = DI::l10n();
if ($openid->validate()) {
$authId = $openid->data['openid_identity'];
if (empty($authId)) {
$logger->info($l10n->t('OpenID protocol error. No ID returned'));
$baseUrl->redirect();
DI::logger()->info($l10n->t('OpenID protocol error. No ID returned'));
DI::baseUrl()->redirect();
}
// NOTE: we search both for normalised and non-normalised form of $authid
@ -61,7 +51,7 @@ class OpenID extends BaseModule
$condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true,
'openid' => [$authId, Strings::normaliseOpenID($authId)]];
$dba = self::getClass(Database::class);
$dba = DI::dba();
$user = $dba->selectFirst('user', [], $condition);
if ($dba->isResult($user)) {
@ -69,13 +59,11 @@ class OpenID extends BaseModule
// successful OpenID login
$session->remove('openid');
/** @var Authentication $auth */
$auth = self::getClass(Authentication::class);
$auth->setForUser(self::getApp(), $user, true, true);
DI::auth()->setForUser(self::getApp(), $user, true, true);
// just in case there was no return url set
// and we fell through
$baseUrl->redirect();
DI::baseUrl()->redirect();
}
// Successful OpenID login - but we can't match it to an existing account.
@ -84,17 +72,17 @@ class OpenID extends BaseModule
$session->set('openid_identity', $authId);
// Detect the server URL
$open_id_obj = new LightOpenID($baseUrl->getHostName());
$open_id_obj = new LightOpenID(DI::baseUrl()->getHostName());
$open_id_obj->identity = $authId;
$session->set('openid_server', $open_id_obj->discover($open_id_obj->identity));
if (intval($config->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) {
if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) {
notice($l10n->t('Account not found. Please login to your existing account to add the OpenID to it.'));
} else {
notice($l10n->t('Account not found. Please register a new account or login to your existing account to add the OpenID to it.'));
}
$baseUrl->redirect('login');
DI::baseUrl()->redirect('login');
}
}
}