Skip to content

Commit

Permalink
Only prevent password login from the login page
Browse files Browse the repository at this point in the history
  • Loading branch information
f-elix committed Jul 24, 2024
1 parent 122baba commit 6f9e829
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function onAfterPluginLoad($event)
$isLoginPage = \Craft::$app->getRequest()->getSegment(1) === 'login';

// only register css and js if we are on the login page
if (!$isConsoleRequest && (bool) $isCPRequest && (bool) $isLoginPage) {
if ((bool) $isCPRequest && (bool) $isLoginPage) {
\Craft::$app->getView()->registerAssetBundle(LoginAsset::class);
}
}
Expand All @@ -84,6 +84,8 @@ public function onBeforeLogin($event)
$client_id = isset($config['client_id']) ? $config['client_id'] : null;
$client_secret = isset($config['client_secret']) ? $config['client_secret'] : null;

$isLoginPage = \Craft::$app->getRequest()->getSegment(1) === 'login';

// only block the user if the email is from sso domain AND the client_id/secret is not set
if (
!empty($domain)
Expand All @@ -93,7 +95,7 @@ public function onBeforeLogin($event)
) {
$request = \Craft::$app->getRequest();
$body = $request->getBodyParams();
if (isset($body['password'])) {
if (isset($body['password']) && $isLoginPage) {
throw new \Exception('Agency users can\'t login with their password. Please use your Google Workspace account.');
}
}
Expand Down

0 comments on commit 6f9e829

Please sign in to comment.