Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Nov 7, 2023
1 parent db9ed84 commit bcbd9d7
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ mri_violations:

dashboard:
target=dashboard npm run compile

oidc:
target=oidc npm run compile

20 changes: 20 additions & 0 deletions modules/my_preferences/php/my_preferences.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,25 @@ class My_Preferences extends \NDB_Form
$this->tpl_data['notification_rows'] = $notification_rows;
//------------------------------------------------------------

$widgets = [];
$modules = $this->loris->getActiveModules();
foreach ($modules as $module) {
if ($module->hasAccess($user)) {
$mwidgets = $module->getWidgets(
'userpreference',
$user,
[],
);
foreach ($mwidgets as $widget) {
if (!($widget instanceof UserPreferenceWidget)) {
continue;
}
$widgets[] = $widget;
}
}
}
$this->tpl_data['module_userpreference_widgets'] = $widgets;

// unique key and password rules
$this->form->addFormRule([&$this, '_validateMyPreferences']);
}
Expand Down Expand Up @@ -468,6 +487,7 @@ class My_Preferences extends \NDB_Form
[
$baseurl . '/js/passwordVisibility.js',
$baseurl . '/my_preferences/js/my_preferences_helper.js',
$baseurl . '/js/components/CSSGrid.js',
]
);
}
Expand Down
21 changes: 20 additions & 1 deletion modules/my_preferences/templates/form_my_preferences.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<br />
<form method="post" name="my_preferences" id="my_preferences" autocomplete="off">
<h3>Password Rules</h3>
<ul>
Expand Down Expand Up @@ -89,6 +88,26 @@
{/foreach}
</tbody>
</table>
{* Add any preferences registered from other modules *}
<div id="module_preferences" style="display: flex">
{section name=widget loop=$module_userpreference_widgets}
{assign var="widget" value=$module_userpreference_widgets[widget]}
<div id="widget_{$widget->componentname}">
<h3>{$widget->title}</h3>
{* Include the widget's javascript before trying to invoke it *}
<script src="{$widget->jsurl}" type="text/javascript"></script>

{* Create a react root to render it into *}
<script>
const el = document.createElement("div");
ReactDOM.createRoot(el).render(
{$widget->componentname}({})
);
document.getElementById("widget_{$widget->componentname}").appendChild(el);
</script>
</div>
{/section}
</div>
<div class="row form-group">
<div class="col-sm-2">
<input class="btn btn-sm btn-primary col-xs-12" name="fire_away" value="Save" type="submit" />
Expand Down
3 changes: 3 additions & 0 deletions modules/oidc/php/callback.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ class Callback extends \NDB_Page
// it was decoded but the nonce doesn't match, error out.
return null;
}
header('Content-Type: text/plain');
var_dump($decoded);
exit;
return $decoded;
} catch (\Exception $e) {
// it couldn't be decoded with this key, try the next.
Expand Down
30 changes: 30 additions & 0 deletions modules/oidc/php/module.class.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace LORIS\oidc;
use LORIS\my_preferences\UserPreferenceWidget;

/**
* Class module implements the basic LORIS module functionality
Expand Down Expand Up @@ -28,4 +29,33 @@ class Module extends \Module
{
return 'OpenID Connect';
}

/**
* {@inheritDoc}
*
* @param string $type The type of widgets to get.
* @param \User $user The user widgets are being retrieved for.
* @param array $options A type dependent list of options to provide
* to the widget.
*
* @return \LORIS\GUI\Widget[]
*/
public function getWidgets(string $type, \User $user, array $options)
{
switch($type) {
case 'userpreference':
$factory = \NDB_Factory::singleton();
$baseURL = $factory->settings()->getBaseURL();
return [
new UserPreferenceWidget(
"External Authentication",
$baseURL . "/oidc/js/AuthenticationPreference.js",
"lorisjs.oidc.AuthenticationPreference.default",
[
],
)
];
}
return [];
}
}
2 changes: 1 addition & 1 deletion src/Middleware/ExceptionHandlingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
) : ResponseInterface {
return $handler->handle($request);
// Catch PHP Fatal errors that aren't exceptions such as type errors
// or out of memory errors
register_shutdown_function(
Expand All @@ -51,7 +52,6 @@ function () {
);

try {
return $handler->handle($request);
/* The order of these catch statements matter and should go from
* most to least specific. Otherwise all Exceptions will be caught
* as their more generic parent class which reduces precision.
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ const lorisModules = {
candidate_profile: ['CandidateInfo'],
api_docs: ['swagger-ui_custom'],
dashboard: ['welcome'],
oidc: ['AuthenticationPreference'],
};
for (const [key] of Object.entries(lorisModules)) {
const target = process.env.target;
Expand Down

0 comments on commit bcbd9d7

Please sign in to comment.