diff options
author | Joas Schilling <coding@schilljs.com> | 2020-07-14 10:52:23 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-07-21 21:21:19 +0300 |
commit | 9543a3670d5dcd911d8a0127ae6b6e6b0b896d8f (patch) | |
tree | 297091387d4ce4c536ce601c557e1172f00ec5a5 /lib | |
parent | 2d327c783c98f3f887aadfc627ca21644feb88cf (diff) |
Register "Registration" as alternative login option via the new public API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 24 | ||||
-rw-r--r-- | lib/RegistrationLoginOption.php | 60 |
2 files changed, 76 insertions, 8 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index fd82a0d..d07b8da 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net> * @@ -24,18 +26,24 @@ namespace OCA\Registration\AppInfo; use OCA\Registration\Capabilities; +use OCA\Registration\RegistrationLoginOption; use OCP\AppFramework\App; -use OC\Authentication\Token\IProvider; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; + +class Application extends App implements IBootstrap { + public const APP_ID = 'registration'; -class Application extends App { public function __construct() { - parent::__construct('registration'); + parent::__construct(self::APP_ID); + } - $container = $this->getContainer(); - $container->registerService(IProvider::class, function ($c) { - return \OC::$server->query(IProvider::class); // TODO needed? - }); + public function register(IRegistrationContext $context): void { + $context->registerAlternativeLogin(RegistrationLoginOption::class); + $context->registerCapability(Capabilities::class); + } - $container->registerCapability(Capabilities::class); + public function boot(IBootContext $context): void { } } diff --git a/lib/RegistrationLoginOption.php b/lib/RegistrationLoginOption.php new file mode 100644 index 0000000..d436574 --- /dev/null +++ b/lib/RegistrationLoginOption.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 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 OCA\Registration; + +use OCA\Registration\AppInfo\Application; +use OCP\Authentication\IAlternativeLogin; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Util; + +class RegistrationLoginOption implements IAlternativeLogin { + + /** @var IURLGenerator */ + protected $url; + /** @var IL10N */ + protected $l; + + public function __construct(IURLGenerator $url, + IL10N $l) { + $this->url = $url; + $this->l = $l; + } + + public function getLabel(): string { + return $this->l->t('Register'); + } + + public function getLink(): string { + return $this->url->linkToRoute('registration.register.askEmail'); + } + + public function getClass(): string { + return 'register-button'; + } + + public function load(): void { + Util::addStyle(Application::APP_ID, 'register-button'); + } +} |