Skip to content

Commit

Permalink
feat: allow config options for fullscreen or custom size popup (#63)
Browse files Browse the repository at this point in the history
* feat: allow config options for fullscreen or custom size popup

* placeholders
  • Loading branch information
imorland authored Sep 18, 2023
1 parent ee587a5 commit 5f6a52b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
8 changes: 7 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
(new Extend\Settings())
->default('fof-oauth.only_icons', false)
->default('fof-oauth.update_email_from_provider', true)
->serializeToForum('fof-oauth.only_icons', 'fof-oauth.only_icons', 'boolVal'),
->serializeToForum('fof-oauth.only_icons', 'fof-oauth.only_icons', 'boolVal')
->default('fof-oauth.popupWidth', 580)
->default('fof-oauth.popupHeight', 400)
->default('fof-oauth.fullscreenPopup', true)
->serializeToForum('fof-oauth.popupWidth', 'fof-oauth.popupWidth', 'intval')
->serializeToForum('fof-oauth.popupHeight', 'fof-oauth.popupHeight', 'intval')
->serializeToForum('fof-oauth.fullscreenPopup', 'fof-oauth.fullscreenPopup', 'boolVal'),

(new Extend\Event())
->listen(OAuthLoginSuccessful::class, Listeners\UpdateEmailFromProvider::class),
Expand Down
22 changes: 22 additions & 0 deletions js/src/admin/components/AuthSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ export default class AuthSettingsPage extends ExtensionPage {
label: app.translator.trans('fof-oauth.admin.settings.update_email_from_provider_label'),
help: app.translator.trans('fof-oauth.admin.settings.update_email_from_provider_help'),
})}
{this.buildSettingComponent({
type: 'boolean',
setting: 'fof-oauth.fullscreenPopup',
label: app.translator.trans('fof-oauth.admin.settings.fullscreen_popup_label'),
help: app.translator.trans('fof-oauth.admin.settings.fullscreen_popup_help'),
})}
{this.buildSettingComponent({
type: 'number',
setting: 'fof-oauth.popupWidth',
label: app.translator.trans('fof-oauth.admin.settings.popup_width_label'),
help: app.translator.trans('fof-oauth.admin.settings.popup_width_help'),
placeholder: 580,
min: 0,
})}
{this.buildSettingComponent({
type: 'number',
setting: 'fof-oauth.popupHeight',
label: app.translator.trans('fof-oauth.admin.settings.popup_height_label'),
help: app.translator.trans('fof-oauth.admin.settings.popup_height_help'),
placeholder: 400,
min: 0,
})}

<hr />

Expand Down
31 changes: 31 additions & 0 deletions js/src/forum/extend/extendLoginSignup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ import SignUpModal from 'flarum/forum/components/SignUpModal';
import ForumApplication from 'flarum/forum/ForumApplication';

export default function () {
extend(LogInButton, 'initAttrs', function (returnedValue, attrs) {
const fullscreen = app.forum.attribute('fof-oauth.fullscreenPopup');

if (fullscreen) {
attrs.onclick = function () {
window.open(app.forum.attribute('baseUrl') + attrs.path, 'logInPopup', 'fullscreen=yes');
};
} else {
// Default values
const defaultWidth = 580;
const defaultHeight = 400;

const width = app.forum.attribute('fof-oauth.popupWidth') || defaultWidth;
const height = app.forum.attribute('fof-oauth.popupHeight') || defaultHeight;

const $window = $(window);

attrs.onclick = function () {
window.open(
app.forum.attribute('baseUrl') + attrs.path,
'logInPopup',
`width=${width},` +
`height=${height},` +
`top=${$window.height() / 2 - height / 2},` +
`left=${$window.width() / 2 - width / 2},` +
'status=no,scrollbars=yes,resizable=no'
);
};
}
});

extend(LogInButtons.prototype, 'items', function (items) {
const onlyIcons = !!app.forum.attribute('fof-oauth.only_icons');
const buttons = app.forum.attribute('fof-oauth').filter(Boolean);
Expand Down
6 changes: 6 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ fof-oauth:
only_icons_label: Only show the Log In Button icons (alternative layout)
update_email_from_provider_label: Update email address from provider
update_email_from_provider_help: If enabled, the user's email address will be updated to match the one provided by the OAuth provider on each login to the forum. Not all providers provide the updated email, in which case this setting will not have any effect with those providers.
fullscreen_popup_label: Use Fullscreen Popup for OAuth
fullscreen_popup_help: When enabled, the OAuth login will open in a fullscreen popup. If this is enabled, the width and height settings will be ignored.
popup_width_label: OAuth Popup Width
popup_width_help: Set the width of the OAuth popup window. This setting will be ignored if "Use Fullscreen Popup for OAuth" is enabled.
popup_height_label: OAuth Popup Height
popup_height_help: Set the height of the OAuth popup window. This setting will be ignored if "Use Fullscreen Popup for OAuth" is enabled.

providers:
callback_url_text: If necessary, set the callback URL to {url}.
Expand Down

0 comments on commit 5f6a52b

Please sign in to comment.