Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
use OC\Authentication\WebAuthn\Manager as WebAuthnManager;
use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OC_App;
use OC_Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Authentication\Events\AlternativeLoginOptionsEvent;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\ILogger;
Expand Down Expand Up @@ -83,6 +84,8 @@ class LoginController extends Controller {
private $initialStateService;
/** @var WebAuthnManager */
private $webAuthnManager;
/** @var IEventDispatcher */
private $dispatcher;

public function __construct(?string $appName,
IRequest $request,
Expand All @@ -96,7 +99,8 @@ public function __construct(?string $appName,
Throttler $throttler,
Chain $loginChain,
IInitialStateService $initialStateService,
WebAuthnManager $webAuthnManager) {
WebAuthnManager $webAuthnManager,
IEventDispatcher $dispatcher) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->config = $config;
Expand All @@ -109,6 +113,7 @@ public function __construct(?string $appName,
$this->loginChain = $loginChain;
$this->initialStateService = $initialStateService;
$this->webAuthnManager = $webAuthnManager;
$this->dispatcher = $dispatcher;
}

/**
Expand Down Expand Up @@ -196,8 +201,11 @@ public function showLoginForm(string $user = null, string $redirect_url = null):
Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']);
Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png'))]);

$event = new AlternativeLoginOptionsEvent();
$this->dispatcher->dispatchTyped($event);

$parameters = [
'alt_login' => OC_App::getAlternativeLogIns(),
'alt_login' => $event->getAlternativeLogins(),
];
return new TemplateResponse(
$this->appName, 'login', $parameters, 'guest'
Expand Down
17 changes: 16 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use OC\Repair;
use OC\ServerNotAvailableException;
use OCP\App\ManagerEvent;
use OCP\Authentication\Events\AlternativeLoginOptionsEvent;
use OCP\ILogger;

/**
Expand Down Expand Up @@ -665,16 +666,30 @@ public static function registerPersonal(string $app, string $page) {

/**
* @param array $entry
* @depreacted 20.0.0 Use \OCP\Authentication\Events\AlternativeLoginOptionsEvent
*/
public static function registerLogIn(array $entry) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also fine with dropping this immediately.
I guess apart from the registration app some apps from https://apps.nextcloud.com/?search=login might need adjustment

if (empty(self::$altLogin)) {
/** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->query(\OCP\EventDispatcher\IEventDispatcher::class);
$dispatcher->addListener(\OCP\Authentication\Events\AlternativeLoginOptionsEvent::class, function (\OCP\Authentication\Events\AlternativeLoginOptionsEvent $event) {
foreach (self::$altLogin as $login) {
$event->addLoginOption($login['name'], $login['href'], $login['style'] ?? '');
}
});
}
self::$altLogin[] = $entry;
}

/**
* @return array
* @depreacted 20.0.0 Use \OCP\Authentication\Events\AlternativeLoginOptionsEvent
*/
public static function getAlternativeLogIns(): array {
return self::$altLogin;
$event = new AlternativeLoginOptionsEvent();
$dispatcher = \OC::$server->query(\OCP\EventDispatcher\IEventDispatcher::class);
$dispatcher->dispatchTyped($event);
return $event->getAlternativeLogins();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCP\Authentication\Events;

use OCP\EventDispatcher\Event;

/**
* @since 20.0.0
*/
class AlternativeLoginOptionsEvent extends Event {

/** @var array */
private $loginOptions;

/**
* @since 20.0.0
*/
public function __construct() {
parent::__construct();

$this->loginOptions = [];
}

/**
* Register a new alternative login option
*
* @param string $name
* @param string $link
* @param string $styleClass
* @since 20.0.0
*/
public function addLoginOption(string $name, string $link, string $styleClass = ''): void {
$this->loginOptions[] = [
'name' => $name,
'href' => $link,
'style' => $styleClass,
];
}

/**
* Get all registered login options
*
* @return array[]
* @since 20.0.0
*/
public function getAlternativeLogins(): array {
return $this->loginOptions;
}
}