Skip to content

Commit

Permalink
legacy registration implemented (+ new settings option)
Browse files Browse the repository at this point in the history
  • Loading branch information
RBoelter committed Mar 3, 2021
1 parent d474243 commit 8b9ff97
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
26 changes: 20 additions & 6 deletions OpenIDPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public function callbackLoadHandler($hookName, $args)
break;
case 'login/index':
case 'login/legacyLogin':
case 'user/register':
case 'login/signOut':
$templateMgr->addStyleSheet('OpenIDPluginStyle', $request->getBaseUrl().'/'.$this->getPluginPath().'/css/style.css');
$templateMgr->addJavaScript('OpenIDPluginScript', $request->getBaseUrl().'/'.$this->getPluginPath().'/js/scripts.js');
$templateMgr->assign('openIDImageURL', $request->getBaseUrl().'/'.$this->getPluginPath().'/images/');
define('HANDLER_CLASS', 'OpenIDLoginHandler');
$args[2] = $this->getPluginPath().'/handler/OpenIDLoginHandler.inc.php';
$this->_addScriptsAndHandler($templateMgr, $request, $args);
break;
case 'user/register':
if(!$request->isPost()) {
$this->_addScriptsAndHandler($templateMgr, $request, $args);
}
break;
}

Expand Down Expand Up @@ -183,5 +183,19 @@ public function manage($args, $request)

return parent::manage($args, $request);
}

/**
* @param $templateMgr
* @param $request
* @param $args
*/
private function _addScriptsAndHandler($templateMgr, $request, $args): void
{
$templateMgr->addStyleSheet('OpenIDPluginStyle', $request->getBaseUrl().'/'.$this->getPluginPath().'/css/style.css');
$templateMgr->addJavaScript('OpenIDPluginScript', $request->getBaseUrl().'/'.$this->getPluginPath().'/js/scripts.js');
$templateMgr->assign('openIDImageURL', $request->getBaseUrl().'/'.$this->getPluginPath().'/images/');
define('HANDLER_CLASS', 'OpenIDLoginHandler');
$args[2] = $this->getPluginPath().'/handler/OpenIDLoginHandler.inc.php';
}
}

5 changes: 4 additions & 1 deletion forms/OpenIDPluginSettingsForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function initData()
'initProvider' => self::PUBLIC_OPENID_PROVIDER,
'provider' => $provider,
'legacyLogin' => key_exists('legacyLogin', $settings) ? $settings['legacyLogin'] : true,
'legacyRegister' => key_exists('legacyRegister', $settings) ? $settings['legacyRegister'] : true,
'disableConnect' => key_exists('disableConnect', $settings) ? $settings['disableConnect'] : false,
'hashSecret' => $settings['hashSecret'],
'generateAPIKey' => $settings['generateAPIKey'] ? $settings['generateAPIKey'] : 0,
Expand All @@ -91,6 +92,7 @@ function initData()
$this->_data = array(
'initProvider' => self::PUBLIC_OPENID_PROVIDER,
'legacyLogin' => true,
'legacyRegister' => false,
'generateAPIKey' => false,
);
}
Expand All @@ -103,7 +105,7 @@ function initData()
function readInputData()
{
$this->readUserVars(
array('provider', 'legacyLogin', 'disableConnect', 'hashSecret', 'generateAPIKey', 'providerSync', 'disableFields')
array('provider', 'legacyLogin', 'legacyRegister', 'disableConnect', 'hashSecret', 'generateAPIKey', 'providerSync', 'disableFields')
);
parent::readInputData();
}
Expand Down Expand Up @@ -143,6 +145,7 @@ function execute(...$functionArgs)
$settings = array(
'provider' => $providerListResult,
'legacyLogin' => $this->getData('legacyLogin'),
'legacyRegister' => $this->getData('legacyRegister'),
'disableConnect' => $this->getData('disableConnect'),
'hashSecret' => $this->getData('hashSecret'),
'generateAPIKey' => $this->getData('generateAPIKey'),
Expand Down
6 changes: 5 additions & 1 deletion handler/OpenIDLoginHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ function index($args, $request)
if ($settingsJson != null) {
$settings = json_decode($settingsJson, true);
$legacyLogin = key_exists('legacyLogin', $settings) && isset($settings['legacyLogin']) ? $settings['legacyLogin'] : false;
$legacyRegister = key_exists('legacyRegister', $settings) && isset($settings['legacyRegister']) ? $settings['legacyRegister'] : false;
$providerList = key_exists('provider', $settings) ? $settings['provider'] : null;
if (isset($providerList)) {
foreach ($providerList as $name => $settings) {
if (key_exists('authUrl', $settings) && !empty($settings['authUrl'])
&& key_exists('clientId', $settings) && !empty($settings['clientId'])) {
if (sizeof($providerList) == 1 && !$legacyLogin) {
if (sizeof($providerList) == 1 && !$legacyLogin && !$legacyRegister) {
$request->redirectUrl(
$settings['authUrl'].
'?client_id='.$settings['clientId'].
Expand Down Expand Up @@ -92,6 +93,9 @@ function index($args, $request)
}
}
}
if ($legacyRegister) {
$linkList['legacyRegister'] = $router->url($request, null, "user", "registerUser");
}
}
if (isset($linkList) && is_array($linkList) && sizeof($linkList) > 0) {
$templateMgr->assign('linkList', $linkList);
Expand Down
Binary file added images/legacyRegister-sign-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ msgid "plugins.generic.openid.settings.legacyLogin.check"
msgstr "Enable legacy login"

msgid "plugins.generic.openid.settings.legacyLogin.desc"
msgstr "Enable this option if you want users to be able to register and login with the application's login form in addition to the OpenID logon."
msgstr "Enable this option if you want users to be able to login with the application's login form in addition to the OpenID logon."

msgid "plugins.generic.openid.settings.legacyRegister.check"
msgstr "Enable legacy registration"

msgid "plugins.generic.openid.settings.legacyRegister.desc"
msgstr "Enable this option if you want users to be able to register with the application's register form in addition to the OpenID logon."

msgid "plugins.generic.openid.settings.step2.connect"
msgstr "Account Connection"
Expand Down Expand Up @@ -247,6 +253,9 @@ msgstr "Sign in with Microsoft"
msgid "plugins.generic.openid.select.provider.apple"
msgstr "Sign in with Apple"

msgid "plugins.generic.openid.select.provider.legacyRegister"
msgstr "Register Account (without Oauth)"

# disabled fields info
msgid "plugins.generic.openid.disables.fields.info"
msgstr "Some information is provided by an authenticated account used to login and cannot be edited.<br /> The data will be synced whenever you log out and login again."
Expand Down
4 changes: 4 additions & 0 deletions templates/settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
{fbvElement type="checkbox" id="legacyLogin" checked=$legacyLogin value=true label="plugins.generic.openid.settings.legacyLogin.check"}
<label class="sub_label">{translate key="plugins.generic.openid.settings.legacyLogin.desc"}</label>
{/fbvFormSection}
{fbvFormSection list=true}
{fbvElement type="checkbox" id="legacyRegister" checked=$legacyRegister value=true label="plugins.generic.openid.settings.legacyRegister.check"}
<label class="sub_label">{translate key="plugins.generic.openid.settings.legacyRegister.desc"}</label>
{/fbvFormSection}
{fbvFormSection list=true}
{fbvElement type="checkbox" id="disableConnect" checked=$disableConnect value=true label="plugins.generic.openid.settings.step2.connect.check"}
<label class="sub_label">{translate key="plugins.generic.openid.settings.step2.connect.desc"}</label>
Expand Down

0 comments on commit 8b9ff97

Please sign in to comment.