Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bc) Move to Craft 5 #2

Merged
merged 4 commits into from
Aug 13, 2024
Merged
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "deuxhuithuit/craft-agency-auth",
"description": "Adds SSO login in the cp with Google",
"type": "craft-plugin",
"version": "1.1.2",
"version": "2.0.0",
"keywords": [
"admin",
"control panel",
Expand All @@ -24,7 +24,7 @@
},
"require": {
"php": "8.1.*|8.2.*|8.3.*",
"craftcms/cms": "^4.0.0"
"craftcms/cms": "^5.0.0"
},
"autoload": {
"psr-4": {
Expand Down
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) {
nitriques marked this conversation as resolved.
Show resolved Hide resolved
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';
nitriques marked this conversation as resolved.
Show resolved Hide resolved

// 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) {
nitriques marked this conversation as resolved.
Show resolved Hide resolved
throw new \Exception('Agency users can\'t login with their password. Please use your Google Workspace account.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/CallbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function actionIndex()

// Make sure password is set
if (!$user->newPassword) {
throw new \Exception('default_password is not set config.');
throw new \Exception('default_password is not set in config.');
}

// Save the user
Expand Down
7 changes: 2 additions & 5 deletions src/web/assets/login/dist/login.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#poweredby {
margin-top: 50px !important;
}

.dhh-btn {
width: 100%;
}
margin-top: 16px;
}
28 changes: 11 additions & 17 deletions src/web/assets/login/dist/login.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
(($) => {
(() => {
'use strict';

const scope = $('body');

const sels = {
ref: '#poweredby'
};

const init = () => {
const ref = scope.find(sels.ref);
const html = $('<a href="/actions/agency-auth/dialog" class="btn dhh-btn" />')
.text('Agency Login');

html.insertBefore(ref);
};

init();
})(jQuery);
const formContainer = document.querySelector('.login-form-container');
if (!formContainer) {
return;
}
const link = document.createElement('a');
link.href = '/actions/agency-auth/dialog';
link.className = 'btn dhh-btn';
link.textContent = 'Agency Login';
formContainer.appendChild(link);
})();
Loading