From e7b830673da798e498a16b68e67257553f6c4384 Mon Sep 17 00:00:00 2001
From: Leone25 <39310565+Leone25@users.noreply.github.com>
Date: Tue, 30 Apr 2024 21:31:48 +0200
Subject: [PATCH 1/9] Now with added Sugo!
---
public/index.php | 3 +-
public/sir.php | 2 +-
public/sugo.php | 58 +++++++++++
src/Authentication.php | 13 +++
src/Ldap.php | 15 ++-
templates/index.php | 2 +
templates/navbar.php | 3 +
templates/sugo.php | 226 +++++++++++++++++++++++++++++++++++++++++
8 files changed, 315 insertions(+), 7 deletions(-)
create mode 100644 public/sugo.php
create mode 100644 templates/sugo.php
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 = $name ?>, your username is = $uid ?> and your ID is = $id ?>
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 @@
Personal
+
+ Sugo
+
Authentication
diff --git a/templates/sugo.php b/templates/sugo.php
new file mode 100644
index 0000000..cf38796
--- /dev/null
+++ b/templates/sugo.php
@@ -0,0 +1,226 @@
+layout('base', ['title' => 'Welcome']) ?>
+
+
+
+
+
+
\ No newline at end of file
From 2cb3db6b293ef20e9409fd98d4ceb6304a063549 Mon Sep 17 00:00:00 2001
From: Leone25 <39310565+Leone25@users.noreply.github.com>
Date: Wed, 1 May 2024 08:43:41 +0200
Subject: [PATCH 2/9] changed button
---
src/Template.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Template.php b/src/Template.php
index 13c92d0..063b9f3 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -31,6 +31,6 @@ public static function telegramColumn($nickname, $id): string
public static function shortListEntry(string $uid, string $cn, ?string $schacpersonaluniquecode): string
{
$schacpersonaluniquecode = $schacpersonaluniquecode ?? 'no matricola';
- return /** @lang HTML */ "$cn , $schacpersonaluniquecode Get SIR ";
+ return /** @lang HTML */ "$cn , $schacpersonaluniquecode Sign SIR ";
}
}
From cbc03a009e646145013c632b9904770c24ad62bb Mon Sep 17 00:00:00 2001
From: Leone25 <39310565+Leone25@users.noreply.github.com>
Date: Wed, 1 May 2024 09:26:22 +0200
Subject: [PATCH 3/9] lint fix
---
public/sugo.php | 8 +++-----
templates/index.php | 4 +++-
templates/sugo.php | 6 ++++--
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/public/sugo.php b/public/sugo.php
index 544bbf3..0dd825e 100644
--- a/public/sugo.php
+++ b/public/sugo.php
@@ -7,8 +7,6 @@
require '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
Authentication::requireLogin();
-
-
$ldap = new Ldap(
CRAUTO_LDAP_URL,
CRAUTO_LDAP_BIND_DN,
@@ -29,12 +27,12 @@
CRAUTO_LDAP_GROUPS_DN,
CRAUTO_LDAP_STARTTLS
);
- $users = $ldap->getUsers(['givenname','sn','signedsir','nsaccountlock', 'mail']);
+ $users = $ldap->getUsers(['givenname', 'sn', 'signedsir', 'nsaccountlock', 'mail']);
if (isset($_GET['uid'])) {
$selectedUser = $_GET['uid'];
}
} else {
- $users = [$ldap->getUser($_SESSION['uid'], ['givenname','sn','signedsir','nsaccountlock', 'mail'])];
+ $users = [$ldap->getUser($_SESSION['uid'], ['givenname', 'sn', 'signedsir', 'nsaccountlock', 'mail'])];
$selectedUser = $_SESSION['uid'];
}
@@ -55,4 +53,4 @@
echo $template->render('sugo', [
'users' => $mappedUsers,
'selectedUser' => $selectedUser
-]);
\ No newline at end of file
+]);
diff --git a/templates/index.php b/templates/index.php
index e48da56..b6861e6 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -7,7 +7,9 @@
Crauto
Creatore e Rimuovitore Autogestito di Utenti che Tutto Offre
-You still haven't signed your SIR! Generate document "; ?>
+You still haven't signed your SIR! Generate document ";
+} ?>
Hi = $name ?>, your username is = $uid ?> and your ID is = $id ?>
Enabled services
What can I access with this account?
diff --git a/templates/sugo.php b/templates/sugo.php
index cf38796..880e0fa 100644
--- a/templates/sugo.php
+++ b/templates/sugo.php
@@ -1,5 +1,7 @@
layout('base', ['title' => 'Welcome']) ?>
+
+$this->layout('base', ['title' => 'Welcome'])
+?>
@@ -10,7 +12,7 @@
data() {
return {
users: = json_encode($users) ?>,
- selectedUser: = $selectedUser ? "'" . str_replace("'", "\'", $selectedUser) . "'" : "null" ?>,
+ selectedUser: = $selectedUser ? "'" . str_replace("'", "\'", $selectedUser) . "'" : 'null' ?>,
selectedUserData: null,
document: null,
finalDocument: null,
From eff8ad4ec3933723ce77cc583e7a4da76dd3da83 Mon Sep 17 00:00:00 2001
From: Ludovico Pavesi
Date: Sun, 5 May 2024 14:48:48 +0200
Subject: [PATCH 4/9] Text and alignment
---
templates/index.php | 6 +++---
templates/navbar.php | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/templates/index.php b/templates/index.php
index b6861e6..d2126bc 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -7,10 +7,10 @@
Crauto
Creatore e Rimuovitore Autogestito di Utenti che Tutto Offre
-You still haven't signed your SIR! Generate document ";
-} ?>
Hi = $name ?>, your username is = $uid ?> and your ID is = $id ?>
+
+ You need to sign your SIR! Sign the SIR
+
Enabled services
What can I access with this account?
diff --git a/templates/navbar.php b/templates/navbar.php
index 40698da..aa39e9a 100644
--- a/templates/navbar.php
+++ b/templates/navbar.php
@@ -16,9 +16,6 @@
Personal
-
- Sugo
-
Authentication
@@ -34,6 +31,9 @@
Groups
+
+ SIR
+
Logout
From 45eb8ae57e4bc3a107b03b917ef34d08a88139eb Mon Sep 17 00:00:00 2001
From: Ludovico Pavesi
Date: Sun, 5 May 2024 17:05:35 +0200
Subject: [PATCH 5/9] Add TEST_MODE_SSO, close #23
And fix a bunch of warnings
---
config/config-example.php | 42 +++++++++++++++++++--------------------
public/personal.php | 4 ++--
src/Authentication.php | 42 +++++++++++++++++++++++++++++----------
src/Ldap.php | 3 ++-
4 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/config/config-example.php b/config/config-example.php
index 0aa3a61..b8a8b07 100644
--- a/config/config-example.php
+++ b/config/config-example.php
@@ -1,27 +1,27 @@
setCertPath('/path/to/my.cert');
@@ -111,7 +133,7 @@ public static function signOut()
$token = $_SESSION['id_token'];
session_destroy();
- if (defined('TEST_MODE') && TEST_MODE) {
+ if (TEST_MODE) {
error_log('TEST_MODE, no need to log out');
} else {
$oidc->signOut($token, CRAUTO_URL . '/logout_done.php');
diff --git a/src/Ldap.php b/src/Ldap.php
index 40d442f..4936697 100644
--- a/src/Ldap.php
+++ b/src/Ldap.php
@@ -5,6 +5,7 @@
use DateTime;
use DateTimeZone;
use InvalidArgumentException;
+use LDAP\Result;
class Ldap
{
@@ -269,7 +270,7 @@ public function getUsers(array $attributes): array
* @param string $uid UID to search
* @param array|null $attributes Attributes to include in search result ("null" for all)
*
- * @return resource|null $sr from ldap_search or none if no users are found
+ * @return array|Result|null $sr from ldap_search or none if no users are found
* @throws LdapException if cannot search or more than one user is found
*/
private function searchByUid(string $uid, ?array $attributes = null)
From a09636fd65e2b9a0c35bc4ca13743664e6e10851 Mon Sep 17 00:00:00 2001
From: Ludovico Pavesi
Date: Sun, 5 May 2024 17:11:36 +0200
Subject: [PATCH 6/9] SIR message updated in real time
---
public/index.php | 19 ++++++++++++++++++-
src/Authentication.php | 3 ---
templates/index.php | 10 ++++++++--
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/public/index.php b/public/index.php
index 95f1458..04eafbd 100644
--- a/public/index.php
+++ b/public/index.php
@@ -5,11 +5,28 @@
require '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
Authentication::requireLogin();
+$error = null;
+$attributes = [];
+try {
+ $ldap = new Ldap(
+ CRAUTO_LDAP_URL,
+ CRAUTO_LDAP_BIND_DN,
+ CRAUTO_LDAP_PASSWORD,
+ CRAUTO_LDAP_USERS_DN,
+ CRAUTO_LDAP_GROUPS_DN,
+ CRAUTO_LDAP_STARTTLS
+ );
+ $attributes = $ldap->getUser($_SESSION['uid'], ['signedsir']);
+} catch (LdapException $e) {
+ $error = $e->getMessage();
+}
+
$template = Template::create();
$template->addData(['currentSection' => 'index'], 'navbar');
echo $template->render('index', [
+ 'error' => $error,
'uid' => $_SESSION['uid'],
'id' => $_SESSION['id'],
'name' => $_SESSION['cn'],
- 'hasSignedSIR' => $_SESSION['signedsir'],
+ 'signedSir' => isset($attributes['signedsir']) && $attributes['signedsir'] === 'true',
]);
diff --git a/src/Authentication.php b/src/Authentication.php
index 4385672..d4dfc4e 100644
--- a/src/Authentication.php
+++ b/src/Authentication.php
@@ -339,12 +339,9 @@ private static function setAttributes(OpenIDConnectClient $oidc, $claims = null,
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/templates/index.php b/templates/index.php
index d2126bc..c71c9a3 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -2,13 +2,19 @@
/** @var $uid string */
/** @var $id string */
/** @var $name string */
-/** @var $signedsir bool */
+/** @var $signedSir bool */
+/** @var $error string|null */
$this->layout('base', ['title' => 'Welcome']) ?>
Crauto
Creatore e Rimuovitore Autogestito di Utenti che Tutto Offre
Hi = $name ?>, your username is = $uid ?> and your ID is = $id ?>
-
+
+
+ Error: = $this->e($error) ?>
+
+
+
You need to sign your SIR! Sign the SIR
Enabled services
From abeb38afab447b1e0266757213b041fbc7896b29 Mon Sep 17 00:00:00 2001
From: Ludovico Pavesi
Date: Sun, 5 May 2024 17:37:38 +0200
Subject: [PATCH 7/9] Rename variables to match LDAP attributes, rename text to
match the variables, rename classes to match Bootstrap classes
And add another test account
---
public/index.php | 2 +-
public/sugo.php | 12 ++++++---
src/Ldap.php | 30 +++++++++++++++++++++
templates/sugo.php | 59 +++++++++++++++++++++++-------------------
templates/userlist.php | 4 +--
5 files changed, 73 insertions(+), 34 deletions(-)
diff --git a/public/index.php b/public/index.php
index 04eafbd..5f979c3 100644
--- a/public/index.php
+++ b/public/index.php
@@ -28,5 +28,5 @@
'uid' => $_SESSION['uid'],
'id' => $_SESSION['id'],
'name' => $_SESSION['cn'],
- 'signedSir' => isset($attributes['signedsir']) && $attributes['signedsir'] === 'true',
+ 'signedSir' => Ldap::optionalBooleanToBool($attributes, 'signedsir')
]);
diff --git a/public/sugo.php b/public/sugo.php
index 0dd825e..3383639 100644
--- a/public/sugo.php
+++ b/public/sugo.php
@@ -39,14 +39,18 @@
$mappedUsers = [];
foreach ($users as $user) {
$mappedUsers[] = [
- 'id' => $user['uid'],
- 'name' => $user['givenname'] . ' ' . $user['sn'],
- 'needsToSign' => !($user['signedsir'] ?? false),
- 'isBlocked' => !($user['nsaccountlock'] ?? false),
+ 'uid' => $user['uid'],
+ 'cn' => $user['cn'],
+ 'needsToSign' => Ldap::optionalBooleanToBool($user, 'signedsir'),
+ 'isLocked' => Ldap::optionalBooleanToBool($user, 'nsaccountlock'),
'email' => $user['mail']
];
}
+usort($mappedUsers, function (array $a, array $b): int {
+ return strcasecmp($a['uid'], $b['uid']);
+});
+
$template = Template::create();
$template->addData(['currentSection' => 'sugo'], 'navbar');
diff --git a/src/Ldap.php b/src/Ldap.php
index 4936697..e0d96fb 100644
--- a/src/Ldap.php
+++ b/src/Ldap.php
@@ -25,6 +25,7 @@ class Ldap
'createtimestamp' => '20191025105022Z',
'modifytimestamp' => '20191025155317Z',
'safetytestdate' => '20160909',
+ 'degreecourse' => 'Ingegneria dell\'Ingegno',
'signedsir' => 'true',
'haskey' => 'true',
'schacpersonaluniquecode' => 's111111',
@@ -46,6 +47,7 @@ class Ldap
'createtimestamp' => '20191025105022Z',
'modifytimestamp' => '20191025155317Z',
'safetytestdate' => '20991104',
+ 'degreecourse' => 'Architettura (dei calcolatori perĂ²)',
'signedsir' => null,
'haskey' => null,
'schacpersonaluniquecode' => 's22222',
@@ -67,6 +69,7 @@ class Ldap
'createtimestamp' => '20191025105022Z',
'modifytimestamp' => '20191025155317Z',
'safetytestdate' => '20201104',
+ 'degreecourse' => 'Ingegneria dell\'Ingegnerizzazione',
'signedsir' => 'true',
'haskey' => null,
'nsaccountlock' => 'true',
@@ -108,6 +111,7 @@ class Ldap
'createtimestamp' => '20191025105022Z',
'modifytimestamp' => '20191025155317Z',
'safetytestdate' => '20201025',
+ 'degreecourse' => 'Ingegneria dell\'Ingegnerizzazione',
'signedsir' => null,
'haskey' => null,
'nsaccountlock' => null,
@@ -119,6 +123,27 @@ class Ldap
'telegramid' => '123456789',
'mail' => 'bro@example.com',
],
+ 'brobruh' => [
+ 'uid' => 'brobruh',
+ 'cn' => 'Bro Bruh',
+ 'givenname' => 'Bro',
+ 'sn' => 'Bruh',
+ 'memberof' => ["cn=Admin,ou=Groups,dc=weeeopen,dc=it", "cn=Gente,ou=Groups,dc=weeeopen,dc=it"],
+ 'createtimestamp' => '20191025105022Z',
+ 'modifytimestamp' => '20191025155317Z',
+ 'safetytestdate' => '20210926',
+ 'degreecourse' => 'Ingegneria Disinformatica',
+ 'signedsir' => null,
+ 'haskey' => null,
+ 'nsaccountlock' => 'true',
+ 'schacpersonaluniquecode' => 's333444555666',
+ 'telegramnickname' => null,
+ 'sshpublickey' => [],
+ 'weeelabnickname' => [],
+ 'description' => '',
+ 'telegramid' => '12345678912345',
+ 'mail' => 'bro@bruh.example',
+ ],
];
private const EXAMPLE_GROUPS = ['Admin', 'Persone', 'Cloud'];
@@ -490,6 +515,11 @@ public static function groupDnToName(string $dn): string
throw new InvalidArgumentException("$dn is not a group DN");
}
+ public static function optionalBooleanToBool(array $attributes, string $var): bool
+ {
+ return isset($attributes[$var]) && $attributes[$var] === 'true';
+ }
+
public function groupNamesToDn(array $names): array
{
if (count($names) <= 0) {
diff --git a/templates/sugo.php b/templates/sugo.php
index 880e0fa..1e8351a 100644
--- a/templates/sugo.php
+++ b/templates/sugo.php
@@ -1,5 +1,6 @@
layout('base', ['title' => 'Welcome'])
?>
@@ -12,19 +13,19 @@
data() {
return {
users: = json_encode($users) ?>,
- selectedUser: = $selectedUser ? "'" . str_replace("'", "\'", $selectedUser) . "'" : 'null' ?>,
+ selectedUser: = $selectedUser ? "'" . json_encode($selectedUser, JSON_UNESCAPED_UNICODE) . "'" : 'null' ?>,
selectedUserData: null,
document: null,
finalDocument: null,
loading: false,
- screen: = $selectedUser ? "'sign'" : "'chooseUser'" ?>,
+ screen: '= $selectedUser ? "sign" : "chooseUser" ?>',
mouseDown: false,
toEmail: null,
}
},
watch: {
screen() {
- if (this.screen == 'sign') {
+ if (this.screen === 'sign') {
history.pushState(null, '', '/sugo.php?uid=' + encodeURIComponent(this.selectedUser));
} else {
history.pushState(null, '', '/sugo.php');
@@ -32,7 +33,7 @@
}
},
mounted() {
- if (this.screen == 'sign') {
+ if (this.screen === 'sign') {
this.sign();
}
},
@@ -40,14 +41,14 @@
needsToSign() {
return this.users.filter(user => user.needsToSign);
},
- isBlocked() {
- return this.users.filter(user => user.isBlocked);
+ isLocked() {
+ return this.users.filter(user => user.isLocked);
},
everyoneElse() {
- return this.users.filter(user => !user.needsToSign && !user.isBlocked);
+ return this.users.filter(user => !user.needsToSign && !user.isLocked);
},
selectedUserData() {
- return this.users.find(user => user.id == this.selectedUser);
+ return this.users.find(user => user.uid === this.selectedUser);
}
},
methods: {
@@ -157,7 +158,7 @@
method: 'POST',
body: formData,
}).then(res => {
- if (res.status == 206) {
+ if (res.status === 206) {
this.screen = 'chooseUser';
this.loading = false;
} else {
@@ -174,7 +175,7 @@
a.download = 'sir.pdf';
a.click();
URL.revokeObjectURL(pdfUrl);
- if (this.users.length == 0) {
+ if (this.users.length === 0) {
// just redirect to the home page
window.location.href = '/';
}
@@ -185,22 +186,26 @@
Sign the SIR
Loading...
-
- Select the person:
-
-
- {{ user.name }} ({{ user.id }})
-
-
- {{ user.name }} ({{ user.id }})
-
-
- {{ user.name }} ({{ user.id }})
-
-
- Sign
+
+
-
+
Back
Clear
@@ -211,7 +216,7 @@
-
+
Email:
diff --git a/templates/userlist.php b/templates/userlist.php
index a806edb..9c754ed 100644
--- a/templates/userlist.php
+++ b/templates/userlist.php
@@ -35,7 +35,7 @@
-
+
@@ -138,7 +138,7 @@
Locked accounts
-
+
From 96dd9cace0085618d9a17ae1954dea8b705e53df Mon Sep 17 00:00:00 2001
From: Ludovico Pavesi
Date: Sun, 5 May 2024 17:51:16 +0200
Subject: [PATCH 8/9] Cleanup and lint fix
---
public/sugo.php | 11 -----------
src/Authentication.php | 2 +-
templates/index.php | 2 +-
templates/sugo.php | 1 +
4 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/public/sugo.php b/public/sugo.php
index 3383639..ff70350 100644
--- a/public/sugo.php
+++ b/public/sugo.php
@@ -2,8 +2,6 @@
namespace WEEEOpen\Crauto;
-use DateTimeZone;
-
require '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
Authentication::requireLogin();
@@ -16,17 +14,8 @@
CRAUTO_LDAP_STARTTLS
);
-$users = [];
$selectedUser = null;
if (Authentication::isAdmin()) {
- $ldap = new Ldap(
- CRAUTO_LDAP_URL,
- CRAUTO_LDAP_BIND_DN,
- CRAUTO_LDAP_PASSWORD,
- CRAUTO_LDAP_USERS_DN,
- CRAUTO_LDAP_GROUPS_DN,
- CRAUTO_LDAP_STARTTLS
- );
$users = $ldap->getUsers(['givenname', 'sn', 'signedsir', 'nsaccountlock', 'mail']);
if (isset($_GET['uid'])) {
$selectedUser = $_GET['uid'];
diff --git a/src/Authentication.php b/src/Authentication.php
index d4dfc4e..6a38adf 100644
--- a/src/Authentication.php
+++ b/src/Authentication.php
@@ -78,7 +78,7 @@ public static function authenticate()
if (TEST_MODE) {
error_log('TEST_MODE, faking authentication');
- switch(TEST_MODE_SSO) {
+ switch (TEST_MODE_SSO) {
case 1:
default:
$_SESSION['uid'] = 'test.administrator';
diff --git a/templates/index.php b/templates/index.php
index c71c9a3..b153128 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -14,7 +14,7 @@
Error: = $this->e($error) ?>
-
+
You need to sign your SIR! Sign the SIR
Enabled services
diff --git a/templates/sugo.php b/templates/sugo.php
index 1e8351a..501b2cf 100644
--- a/templates/sugo.php
+++ b/templates/sugo.php
@@ -1,4 +1,5 @@
layout('base', ['title' => 'Welcome'])
From fefe5782619c1191776861586f1015f5b05cccc3 Mon Sep 17 00:00:00 2001
From: Leone25 <39310565+Leone25@users.noreply.github.com>
Date: Sun, 5 May 2024 22:01:53 +0200
Subject: [PATCH 9/9] added missing signatures, file name and download button
---
templates/sugo.php | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/templates/sugo.php b/templates/sugo.php
index 501b2cf..864974d 100644
--- a/templates/sugo.php
+++ b/templates/sugo.php
@@ -14,8 +14,7 @@
data() {
return {
users: = json_encode($users) ?>,
- selectedUser: = $selectedUser ? "'" . json_encode($selectedUser, JSON_UNESCAPED_UNICODE) . "'" : 'null' ?>,
- selectedUserData: null,
+ selectedUser: = $selectedUser ? json_encode($selectedUser, JSON_UNESCAPED_UNICODE) : 'null' ?>,
document: null,
finalDocument: null,
loading: false,
@@ -135,7 +134,19 @@
// add the signature
let signatureBuffer = Uint8Array.from(atob(signatureData.split(',')[1]), c => c.charCodeAt(0));
let signatureImage = await pdf.embedPng(signatureBuffer);
- thirdPage.drawImage(signatureImage, {
+ thirdPage.drawImage(signatureImage, { // guanti
+ x: 355,
+ y: 592,
+ width: 80,
+ height: 40,
+ });
+ thirdPage.drawImage(signatureImage, { // cappa
+ x: 260,
+ y: 460,
+ width: 80,
+ height: 40,
+ });
+ thirdPage.drawImage(signatureImage, { // end of document
x: 360,
y: 110,
width: 180,
@@ -147,7 +158,7 @@
this.download(); // temp
this.loading = false;
},
- send() {
+ send() { // currently unused as we don't have an email endpoint
if (!this.toEmail || this.loading) {
return;
}
@@ -168,15 +179,22 @@
}
});
},
+ async downloadBlank() {
+ await this.sign();
+ this.loading = true;
+ this.finalDocument = this.document;
+ this.download();
+ this.loading = false;
+ },
download() {
let pdfBlob = new Blob([this.finalDocument], {type: 'application/pdf'});
let pdfUrl = URL.createObjectURL(pdfBlob);
let a = document.createElement('a');
a.href = pdfUrl;
- a.download = 'sir.pdf';
+ a.download = `sir-${this.selectedUser}.pdf`;
a.click();
URL.revokeObjectURL(pdfUrl);
- if (this.users.length === 0) {
+ if (this.users.length === 1) {
// just redirect to the home page
window.location.href = '/';
}
@@ -202,7 +220,8 @@
{{ user.cn }} ({{ user.uid }})
- View and Sign
+ Sign
+ View