Rebase for OpenId & Hovercard
This commit is contained in:
parent
2660edbb48
commit
651d693270
|
@ -9,6 +9,7 @@ use Friendica\BaseModule;
|
||||||
use Friendica\Core\Config\Configuration;
|
use Friendica\Core\Config\Configuration;
|
||||||
use Friendica\Core\L10n\L10n;
|
use Friendica\Core\L10n\L10n;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
|
use Friendica\DI;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
@ -31,15 +32,12 @@ class HoverCard extends BaseModule
|
||||||
$nickname = $parameters['profile'];
|
$nickname = $parameters['profile'];
|
||||||
$profile = 0;
|
$profile = 0;
|
||||||
} else {
|
} else {
|
||||||
/** @var L10n $l10n */
|
throw new NotFoundException(DI::l10n()->t('No profile'));
|
||||||
$l10n = self::getClass(L10n::class);
|
|
||||||
throw new NotFoundException($l10n->t('No profile'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile::load($a, $nickname, $profile);
|
Profile::load($a, $nickname, $profile);
|
||||||
|
|
||||||
/** @var Page $page */
|
$page = DI::page();
|
||||||
$page = self::getClass(Page::class);
|
|
||||||
|
|
||||||
if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
|
if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
|
||||||
$page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
|
$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";
|
$page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Configuration $config */
|
|
||||||
$config = self::getClass(Configuration::class);
|
|
||||||
// check if blocked
|
// 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 = $a->profile['pub_keywords'] ?? '';
|
||||||
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
|
$keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords);
|
||||||
if (strlen($keywords)) {
|
if (strlen($keywords)) {
|
||||||
|
@ -63,8 +59,7 @@ class HoverCard extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var BaseURL $baseUrl */
|
$baseUrl = DI::baseUrl();
|
||||||
$baseUrl = self::getClass(BaseURL::class);
|
|
||||||
|
|
||||||
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
|
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use Friendica\Core\Config\Configuration;
|
||||||
use Friendica\Core\L10n\L10n;
|
use Friendica\Core\L10n\L10n;
|
||||||
use Friendica\Core\Session\ISession;
|
use Friendica\Core\Session\ISession;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\DI;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use LightOpenID;
|
use LightOpenID;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -20,37 +21,26 @@ class OpenID extends BaseModule
|
||||||
{
|
{
|
||||||
public static function content(array $parameters = [])
|
public static function content(array $parameters = [])
|
||||||
{
|
{
|
||||||
/** @var Configuration $config */
|
if (DI::config()->get('system', 'no_openid')) {
|
||||||
$config = self::getClass(Configuration::class);
|
DI::baseUrl()->redirect();
|
||||||
|
|
||||||
/** @var BaseURL $baseUrl */
|
|
||||||
$baseUrl = self::getClass(BaseURL::class);
|
|
||||||
|
|
||||||
if ($config->get('system', 'no_openid')) {
|
|
||||||
$baseUrl->redirect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var LoggerInterface $logger */
|
DI::logger()->debug('mod_openid.', ['request' => $_REQUEST]);
|
||||||
$logger = self::getClass(LoggerInterface::class);
|
|
||||||
|
|
||||||
$logger->debug('mod_openid.', ['request' => $_REQUEST]);
|
$session = DI::session();
|
||||||
|
|
||||||
/** @var ISession $session */
|
|
||||||
$session = self::getClass(ISession::class);
|
|
||||||
|
|
||||||
if (!empty($_GET['openid_mode']) && !empty($session->get('openid'))) {
|
if (!empty($_GET['openid_mode']) && !empty($session->get('openid'))) {
|
||||||
|
|
||||||
$openid = new LightOpenID($baseUrl->getHostname());
|
$openid = new LightOpenID(DI::baseUrl()->getHostname());
|
||||||
|
|
||||||
/** @var L10n $l10n */
|
$l10n = DI::l10n();
|
||||||
$l10n = self::getClass(L10n::class);
|
|
||||||
|
|
||||||
if ($openid->validate()) {
|
if ($openid->validate()) {
|
||||||
$authId = $openid->data['openid_identity'];
|
$authId = $openid->data['openid_identity'];
|
||||||
|
|
||||||
if (empty($authId)) {
|
if (empty($authId)) {
|
||||||
$logger->info($l10n->t('OpenID protocol error. No ID returned'));
|
DI::logger()->info($l10n->t('OpenID protocol error. No ID returned'));
|
||||||
$baseUrl->redirect();
|
DI::baseUrl()->redirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: we search both for normalised and non-normalised form of $authid
|
// 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,
|
$condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true,
|
||||||
'openid' => [$authId, Strings::normaliseOpenID($authId)]];
|
'openid' => [$authId, Strings::normaliseOpenID($authId)]];
|
||||||
|
|
||||||
$dba = self::getClass(Database::class);
|
$dba = DI::dba();
|
||||||
|
|
||||||
$user = $dba->selectFirst('user', [], $condition);
|
$user = $dba->selectFirst('user', [], $condition);
|
||||||
if ($dba->isResult($user)) {
|
if ($dba->isResult($user)) {
|
||||||
|
@ -69,13 +59,11 @@ class OpenID extends BaseModule
|
||||||
// successful OpenID login
|
// successful OpenID login
|
||||||
$session->remove('openid');
|
$session->remove('openid');
|
||||||
|
|
||||||
/** @var Authentication $auth */
|
DI::auth()->setForUser(self::getApp(), $user, true, true);
|
||||||
$auth = self::getClass(Authentication::class);
|
|
||||||
$auth->setForUser(self::getApp(), $user, true, true);
|
|
||||||
|
|
||||||
// just in case there was no return url set
|
// just in case there was no return url set
|
||||||
// and we fell through
|
// and we fell through
|
||||||
$baseUrl->redirect();
|
DI::baseUrl()->redirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successful OpenID login - but we can't match it to an existing account.
|
// 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);
|
$session->set('openid_identity', $authId);
|
||||||
|
|
||||||
// Detect the server URL
|
// Detect the server URL
|
||||||
$open_id_obj = new LightOpenID($baseUrl->getHostName());
|
$open_id_obj = new LightOpenID(DI::baseUrl()->getHostName());
|
||||||
$open_id_obj->identity = $authId;
|
$open_id_obj->identity = $authId;
|
||||||
$session->set('openid_server', $open_id_obj->discover($open_id_obj->identity));
|
$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.'));
|
notice($l10n->t('Account not found. Please login to your existing account to add the OpenID to it.'));
|
||||||
} else {
|
} else {
|
||||||
notice($l10n->t('Account not found. Please register a new account or login to your existing account to add the OpenID to it.'));
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue