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

Fixed PHP 8.x related bug #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions forms/OpenIDStep2Form.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ private function _registerUser()
$user = null;
}

// allow other plugins to provide user data (i.e. orcidProfile)
HookRegistry::call('openid::registerUser', array($this,&$user));

return $user;
}
}
32 changes: 26 additions & 6 deletions handler/OpenIDHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,26 @@ function doAuthentication($args, $request, $provider = null)
Validation::registerUserSession($user, $reason, true);

self::updateUserDetails($tokenPayload, $user, $request, $selectedProvider);
if ($user->hasRole(

// check if the user tried to access a specific page
// we needed to set the source as a session variable to work with openId providers
$session = $request->getSession();
$source = $session->getSessionVar('source');
$session->unsetSessionVar('source', $source);
$sessionDao = DAORegistry::getDAO('SessionDAO');
$sessionDao->updateObject($session);

if ($source != '') {
// The user tried to access a specific page before authentication: load that page
return $request->redirectUrl($source);
}
elseif ($user->hasRole(
[ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER, ROLE_ID_ASSISTANT],
$contextId
)) {
return $request->redirect($context, 'submissions');
return $request->redirect($request->getRequestedContextPath(), 'submissions');
} else {
return $request->redirect($context, 'user', 'profile', null, $args);
return $request->redirect($request->getRequestedContextPath(), 'user', 'profile', null, $args);
}
} elseif ($user->getDisabled()) {
$reason = $user->getDisabledReason();
Expand All @@ -110,7 +123,7 @@ function doAuthentication($args, $request, $provider = null)
$ssoErrors['sso_error'] = !isset($publicKey) ? 'connect_key' : 'connect_data';
}

return $request->redirect($context, 'login', null, null, isset($ssoErrors) ? $ssoErrors : null);
return $request->redirect($request->getRequestedContextPath(), 'login', null, null, isset($ssoErrors) ? $ssoErrors : null);
}


Expand All @@ -129,9 +142,15 @@ function registerOrConnect($args, $request)
$this->setupTemplate($request);
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pageTitle', 'user.login.registrationComplete');

// Register the jQuery script before the orcidProfile js is executed
$min = Config::getVar('general', 'enable_minified') ? '.min' : '';
$jqueryUrl = $request->getBaseUrl() . '/lib/pkp/lib/vendor/components/jquery/jquery' . $min . '.js';
$templateMgr->assign('jqueryUrl', $jqueryUrl);

$templateMgr->display('frontend/pages/userRegisterComplete.tpl');
} elseif (!$request->isPost()) {
$request->redirect($context, 'login');
$request->redirect($request->getRequestedContextPath(), 'login');
} else {
$plugin = PluginRegistry::getPlugin('generic', KEYCLOAK_PLUGIN_NAME);
import($plugin->getPluginPath().'/forms/OpenIDStep2Form');
Expand All @@ -140,7 +159,7 @@ function registerOrConnect($args, $request)
if (!$regForm->validate()) {
$regForm->display($request);
} elseif ($regForm->execute()) {
$request->redirect($context, 'openid', 'registerOrConnect');
$request->redirect($request->getRequestedContextPath(), 'openid', 'registerOrConnect');
} else {
$regForm->addError('', '');
$regForm->display($request);
Expand Down Expand Up @@ -174,6 +193,7 @@ public static function updateUserDetails($payload, $user, $request, $selectedPro
$user->setOrcid($payload['id']);
}
}

$userDao->updateObject($user);
}

Expand Down
15 changes: 12 additions & 3 deletions handler/OpenIDLoginHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function index($args, $request)
$contextId = ($context == null) ? 0 : $context->getId();
$settingsJson = $plugin->getSetting($contextId, 'openIDSettings');

// Did the user try to access a specific page?
// Then we want to preserve this information to redirect correctly after login
$source = $request->getUserVar('source');
$session = $request->getSession();
$session->setSessionVar('source', $source);
$sessionDao = DAORegistry::getDAO('SessionDAO');
$sessionDao->updateObject($session);

if ($settingsJson != null) {
$settings = json_decode($settingsJson, true);
$legacyLogin = key_exists('legacyLogin', $settings) && isset($settings['legacyLogin']) ? $settings['legacyLogin'] : false;
Expand All @@ -72,7 +80,8 @@ function index($args, $request)
$settings['authUrl'].
'?client_id='.$settings['clientId'].
'&response_type=code&scope=openid&redirect_uri='.
$router->url($request, null, "openid", "doAuthentication", null, array('provider' => $name))
$router->url($request, null, "openid", "doAuthentication", null, array('provider' => $name),null,true)
//($source != '' ? urlencode('&state=' . $source) : '')
);

return false;
Expand Down Expand Up @@ -130,7 +139,7 @@ function index($args, $request)
return $templateMgr->display($plugin->getTemplateResource('openidLogin.tpl'));
}

$request->redirect(Application::get()->getRequest()->getContext(), 'index');
$request->redirect($request->getRequestedContextPath(), 'index');

return false;
}
Expand Down Expand Up @@ -199,7 +208,7 @@ function signOut($args, $request)
}
}
}
$request->redirect(Application::get()->getRequest()->getContext(), 'index');
$request->redirect($request->getRequestedContextPath(), 'index');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ msgid "plugins.generic.openid.disables.fields.info.api"
msgstr "The API key is automatically generated by a plugin."

msgid "plugins.generic.openid.disables.fields.info.password"
msgstr "You are using a single sign-on authentication provider to log in, so you must change your password on the provider's account page."
msgstr "You are using a single sign-on authentication provider to log in, so you must change your password on the provider's account page."
7 changes: 7 additions & 0 deletions tarExclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.github
cypress
docker
docker-compose.yaml
composer.json
composer.lock
tarExclude.txt
96 changes: 48 additions & 48 deletions templates/authStep2.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* Display the OpenID Auth second step.
*}
{include file="frontend/components/header.tpl" pageTitle="plugins.generic.openid.step2.title"}
<div class="page page_oauth">
<div>
{include file="frontend/components/breadcrumbs.tpl" currentTitleKey="plugins.generic.openid.step2.title"}
<form class="cmp_form cmp_form oauth" id="oauth" method="post" action="{url page="openid" op="registerOrConnect"}">
<form id="oauth" method="post" action="{url page="openid" op="registerOrConnect"}">
{csrf}
<input type="hidden" name="oauthId" id="oauthId" value="{$oauthId}">
<input type="hidden" name="selectedProvider" id="selectedProvider" value="{$selectedProvider}">
Expand All @@ -40,113 +40,113 @@
<li><span id='showRegisterForm'
class='step2-choice-links'>{translate key="plugins.generic.openid.step2.choice.no" journalName=$siteTitle|escape}</span></li>
</ul>
{/if}
{/if}
<div {if empty($disableConnect) || $disableConnect != "1" }id="register-form"{/if} class="page_register">
<fieldset class="register">
<p class="cmp_notification warning">
{translate key="plugins.generic.openid.step2.help" journalName=$siteTitle|escape}
</p>
<p>
{translate key="plugins.generic.openid.step2.help" journalName=$siteTitle|escape}
</p>
<fieldset class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
{if $returnTo == 'register'}
{include file="common/formErrors.tpl"}
{/if}
<div class="fields">
<div class="given_name">
<label>
<span class="label">
<div class="sm:col-span-4">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="user.givenName"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span aria-hidden="true">*</span>
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<input type="text" name="givenName" id="givenName" value="{$givenName|escape}" maxlength="255" required aria-required="true">
<input class="col-span-2" type="text" name="givenName" id="givenName" value="{$givenName|escape}" maxlength="255" required aria-required="true">
</label>
</div>
<div class="family_name">
<label>
<span class="label">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="user.familyName"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<input type="text" name="familyName" id="familyName" value="{$familyName|escape}" maxlength="255">
<input class="col-span-2" type="text" name="familyName" id="familyName" value="{$familyName|escape}" maxlength="255">
</label>
</div>
<div class="email">
<label>
<span class="label">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="user.email"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<input type="email" name="email" id="email" value="{$email|escape}" maxlength="90" required aria-required="true">
<input class="col-span-2" type="email" name="email" id="email" value="{$email|escape}" maxlength="90" required aria-required="true">
</label>
</div>
<div class="username">
<label>
<span class="label">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="user.username"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<input type="text" name="username" id="username" value="{$username|escape}" maxlength="32" required aria-required="true">
<input class="col-span-2" type="text" name="username" id="username" value="{$username|escape}" maxlength="32" required aria-required="true">
</label>
</div>
<div class="affiliation">
<label>
<span class="label">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="user.affiliation"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<input type="text" name="affiliation" id="affiliation" value="{$affiliation|escape}" required aria-required="true">
<input class="col-span-2" type="text" name="affiliation" id="affiliation" value="{$affiliation|escape}" required aria-required="true">
</label>
</div>
<div class="country">
<label>
<span class="label">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label class="inline-grid grid-cols-3 gap-4">
<span>
{translate key="common.country"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
<select name="country" id="country" required aria-required="true">
<select class="col-span-2" name="country" id="country" required aria-required="true">
<option></option>
{html_options options=$countries selected=$country}
</select>
</label>
</div>
</div>
</fieldset>
<fieldset class="consent">
<fieldset class="mt-10 grid grid-cols-1 gap-y-2 sm:grid-cols-6">
{if isset($currentContext) and $currentContext->getData('privacyStatement')}
{* Require the user to agree to the terms of the privacy policy *}
<div class="fields">
<div class="optin optin-privacy">
<div class="sm:col-span-4">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label>
<input type="checkbox" name="privacyConsent" value="1" required{if $privacyConsent} checked="checked"{/if}>
{capture assign="privacyUrl"}{url router=$smarty.const.ROUTE_PAGE page="about" op="privacy"}{/capture}
{translate key="user.register.form.privacyConsent" privacyUrl=$privacyUrl}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</label>
</div>
</div>
{/if}
{* Ask the user to opt into public email notifications *}
<div class="fields">
<div class="optin optin-email">
<div class="sm:col-span-4">
<div class="block text-sm font-medium leading-6 text-gray-900">
<label>
<input type="checkbox" name="emailConsent" id="emailConsent" value="1" {if $emailConsent} checked="checked"{/if}>
{translate key="user.register.form.emailConsent"}
Expand Down Expand Up @@ -201,7 +201,7 @@
</fieldset>
{/if}
<div class="buttons">
<button class="submit" type="submit" name="register">
<button class="rounded-md bg-sky-600 mx-3 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-sky-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" type="submit" name="register">
{translate key="plugins.generic.openid.step2.complete.btn"}
</button>
</div>
Expand All @@ -220,7 +220,7 @@
<span class="label">
{translate key="plugins.generic.openid.step2.connect.username"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
Expand All @@ -233,7 +233,7 @@
<span class="label">
{translate key="user.password"}
<span class="required" aria-hidden="true">*</span>
<span class="pkp_screen_reader">
<span class="sr-only">
{translate key="common.required"}
</span>
</span>
Expand Down
3 changes: 2 additions & 1 deletion templates/openidLogin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<li class="page_login">
<form class="cmp_form cmp_form login" id="login" method="post" action="{$loginUrl}">
{csrf}
<input type="hidden" name="source" value="{$source|default:""|escape}" />
<fieldset class="fields">
<div class="username">
<label>
Expand Down Expand Up @@ -101,7 +102,7 @@
<li class="margin-top-30"><strong>{translate key='plugins.generic.openid.select.provider.help'}</strong></li>
{foreach from=$linkList key=name item=url}
{if $name == 'custom'}
<li><a id="openid-provider-{$name}" href="{$url}">
<li><a id="openid-provider-{$name}" href="{$url}%26source={$source|default:""|escape:"url"}">
<div>
{if $customBtnImg}
<img src="{$customBtnImg}" alt="{$name}">
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<version>
<application>openid</application>
<type>plugins.generic</type>
<release>3.3.0.7</release>
<date>2021-03-12</date>
<release>3.3.0.13.21</release>
<date>2024-08-12</date>
<lazy-load>1</lazy-load>
<sitewide>1</sitewide>
<class>OpenIDPlugin</class>
Expand Down