diff --git a/public/index.php b/public/index.php index 04ce537..95f1458 100644 --- a/public/index.php +++ b/public/index.php @@ -10,5 +10,6 @@ echo $template->render('index', [ 'uid' => $_SESSION['uid'], 'id' => $_SESSION['id'], - 'name' => $_SESSION['cn'] + 'name' => $_SESSION['cn'], + 'hasSignedSIR' => $_SESSION['signedsir'], ]); diff --git a/public/sir.php b/public/sir.php index f8dae35..063317a 100644 --- a/public/sir.php +++ b/public/sir.php @@ -9,7 +9,7 @@ require '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; Authentication::requireLogin(); -if (!Authentication::isAdmin()) { +if (!Authentication::isAdmin() && !isset($_GET['uid']) && $_GET['uid'] !== $_SESSION['uid']) { $template = Template::create(); echo $template->render('403'); exit; diff --git a/public/sugo.php b/public/sugo.php new file mode 100644 index 0000000..544bbf3 --- /dev/null +++ b/public/sugo.php @@ -0,0 +1,58 @@ +getUsers(['givenname','sn','signedsir','nsaccountlock', 'mail']); + if (isset($_GET['uid'])) { + $selectedUser = $_GET['uid']; + } +} else { + $users = [$ldap->getUser($_SESSION['uid'], ['givenname','sn','signedsir','nsaccountlock', 'mail'])]; + $selectedUser = $_SESSION['uid']; +} + +$mappedUsers = []; +foreach ($users as $user) { + $mappedUsers[] = [ + 'id' => $user['uid'], + 'name' => $user['givenname'] . ' ' . $user['sn'], + 'needsToSign' => !($user['signedsir'] ?? false), + 'isBlocked' => !($user['nsaccountlock'] ?? false), + 'email' => $user['mail'] + ]; +} + +$template = Template::create(); +$template->addData(['currentSection' => 'sugo'], 'navbar'); + +echo $template->render('sugo', [ + 'users' => $mappedUsers, + 'selectedUser' => $selectedUser +]); \ No newline at end of file diff --git a/src/Authentication.php b/src/Authentication.php index 396e6e6..70c4b76 100644 --- a/src/Authentication.php +++ b/src/Authentication.php @@ -81,6 +81,7 @@ public static function authenticate() $_SESSION['uid'] = 'test.administrator'; $_SESSION['id'] = 'fake:example:68048769-c06d-4873-adf6-dbfa6b0afcd3'; $_SESSION['cn'] = 'Test Administrator'; + $_SESSION['hasSignedSIR'] = false; $_SESSION['groups'] = ['HR']; $_SESSION['expires'] = PHP_INT_MAX; $_SESSION['refresh_token'] = 'refresh_token'; @@ -307,9 +308,21 @@ private static function setAttributes(OpenIDConnectClient $oidc, $claims = null, $refresh_token = $oidc->getRefreshToken(); $id_token = $idt ?? $oidc->getIdToken(); + $ldap = new Ldap( + CRAUTO_LDAP_URL, + CRAUTO_LDAP_BIND_DN, + CRAUTO_LDAP_PASSWORD, + CRAUTO_LDAP_USERS_DN, + CRAUTO_LDAP_GROUPS_DN, + CRAUTO_LDAP_STARTTLS + ); + + $ldapInfo = $ldap->getUser($uid, ['signedsir']); + $_SESSION['uid'] = $uid; $_SESSION['id'] = $id; $_SESSION['cn'] = $cn; + $_SESSION['signedsir'] = $ldapInfo['signedsir'] ?? false; // This won't updated until the next login but good enough $_SESSION['groups'] = $groups; $_SESSION['expires'] = $exp; diff --git a/src/Ldap.php b/src/Ldap.php index 74f4abd..40d442f 100644 --- a/src/Ldap.php +++ b/src/Ldap.php @@ -33,7 +33,8 @@ class Ldap 'weeelabnickname' => ['io'], 'websitedescription' => "Il capo supremo\nSu due righe", 'description' => '', - 'nsaccountlock' => null + 'nsaccountlock' => null, + 'mail' => 'admin@example.com', ], 'alice' => [ 'uid' => 'alice', @@ -53,7 +54,8 @@ class Ldap 'weeelabnickname' => [], 'websitedescription' => 'Persona', 'description' => '', - 'nsaccountlock' => 'true' + 'nsaccountlock' => 'true', + 'mail' => 'alice@example.com', ], 'brodino' => [ 'uid' => 'brodino', @@ -72,7 +74,8 @@ class Ldap 'sshpublickey' => [], 'weeelabnickname' => [], 'description' => '', - 'telegramnickname' => 'brodino' + 'telegramnickname' => 'brodino', + 'mail' => 'brodino@example.com', ], 'bob' => [ 'uid' => 'bob', @@ -92,7 +95,8 @@ class Ldap 'sshpublickey' => [], 'weeelabnickname' => [], 'description' => '', - 'nsaccountlock' => null + 'nsaccountlock' => null, + 'mail' => 'bob@example.com', ], 'broski' => [ 'uid' => 'broski', @@ -111,7 +115,8 @@ class Ldap 'sshpublickey' => [], 'weeelabnickname' => [], 'description' => '', - 'telegramid' => '123456789' + 'telegramid' => '123456789', + 'mail' => 'bro@example.com', ], ]; private const EXAMPLE_GROUPS = ['Admin', 'Persone', 'Cloud']; diff --git a/templates/index.php b/templates/index.php index 0d4bd64..e48da56 100644 --- a/templates/index.php +++ b/templates/index.php @@ -2,10 +2,12 @@ /** @var $uid string */ /** @var $id string */ /** @var $name string */ +/** @var $signedsir bool */ $this->layout('base', ['title' => 'Welcome']) ?>

Crauto

Creatore e Rimuovitore Autogestito di Utenti che Tutto Offre +You still haven't signed your SIR! Generate document

"; ?>

Hi , your username is and your ID is

Enabled services

What can I access with this account?

diff --git a/templates/navbar.php b/templates/navbar.php index 547cc35..40698da 100644 --- a/templates/navbar.php +++ b/templates/navbar.php @@ -16,6 +16,9 @@ +