-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move from app.php to Application.php
Use event `OCP\User\Events\BeforeUserLoggedInEvent`
- Loading branch information
Showing
4 changed files
with
74 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2017 Lukas Reschke <[email protected]> | ||
* | ||
* @author Benjamin Gaussorgues <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
|
@@ -16,33 +21,31 @@ | |
* | ||
* 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\LimitLoginToIp\AppInfo; | ||
|
||
$l10n = \OC::$server->getL10N('limit_login_to_ip'); | ||
$config = \OC::$server->getConfig(); | ||
$request = \OC::$server->getRequest(); | ||
$urlGenerator = \OC::$server->getURLGenerator(); | ||
$isLoginPage = parse_url($request->getRequestUri(), PHP_URL_PATH) === $urlGenerator->linkToRoute('core.login.showLoginForm'); | ||
use OCA\LimitLoginToIp\LoginHookListener; | ||
use OCP\AppFramework\App; | ||
use OCP\AppFramework\Bootstrap\IBootContext; | ||
use OCP\AppFramework\Bootstrap\IBootstrap; | ||
use OCP\AppFramework\Bootstrap\IRegistrationContext; | ||
use OCP\User\Events\BeforeUserLoggedInEvent; | ||
|
||
$loginHookListener = new \OCA\LimitLoginToIp\LoginHookListener( | ||
$config, | ||
$request, | ||
$urlGenerator, | ||
$isLoginPage | ||
); | ||
class Application extends App implements IBootstrap { | ||
public const APP_ID = 'limit_login_to_ip'; | ||
|
||
if(!$loginHookListener->isLoginAllowed()) { | ||
if($isLoginPage) { | ||
header('Location: ' . \OC::$WEBROOT . '/index.php/apps/limit_login_to_ip/denied'); | ||
exit(); | ||
public function __construct() { | ||
parent::__construct(self::APP_ID); | ||
} | ||
|
||
\OCP\Util::connectHook( | ||
'OC_User', | ||
'pre_login', | ||
$loginHookListener, | ||
'handleLoginRequest' | ||
); | ||
public function register(IRegistrationContext $context): void { | ||
$context->registerEventListener( | ||
BeforeUserLoggedInEvent::class, | ||
LoginHookListener::class, | ||
); | ||
} | ||
|
||
public function boot(IBootContext $context): void { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters