diff --git a/include/lucidAuth.functions.php b/include/lucidAuth.functions.php index cc56ef6..11352c9 100644 --- a/include/lucidAuth.functions.php +++ b/include/lucidAuth.functions.php @@ -76,7 +76,7 @@ function storeToken (string $secureToken, string $qualifiedUsername, string $htt catch (Exception $e) { return ['status' => 'Fail', 'reason' => $e]; } - + // Save authentication token in cookie clientside $cookieDomain = array_values(array_filter($settings->Session['CookieDomains'], function ($value) use ($httpHost) { // Check if $_SERVER['HTTP_HOST'] matches any of the configured domains (either explicitly or as a subdomain) @@ -114,9 +114,9 @@ function validateToken (string $secureToken) { // Retrieve all authentication tokens from database matching username $pdoQuery = $pdoDB->prepare(' - SELECT SecureToken.Value + SELECT User.Id, SecureToken.Value FROM SecureToken - LEFT JOIN User + LEFT JOIN User ON (User.Id=SecureToken.UserId) WHERE User.Username = :username '); @@ -126,6 +126,7 @@ function validateToken (string $secureToken) { foreach($pdoQuery->fetchAll(PDO::FETCH_ASSOC) as $row) { try { $storedTokens[] = JWT::decode($row['Value'], base64_decode($settings->JWT['PrivateKey_base64']), $settings->JWT['Algorithm']); + $currentUserId = $row['Id']; } catch (Exception $e) { continue; } @@ -137,7 +138,8 @@ function validateToken (string $secureToken) { })) === 1) { return [ 'status' => 'Success', - 'name' => $jwtPayload->name + 'name' => $jwtPayload->name, + 'uid' => $currentUserId ]; } else { if ($settings->Debug['LogToFile']) { diff --git a/include/lucidAuth.template.php b/include/lucidAuth.template.php index 9dc8689..4572173 100644 --- a/include/lucidAuth.template.php +++ b/include/lucidAuth.template.php @@ -33,7 +33,7 @@ $pageLayout['full'] = <<<'FULL' FULL; -$pageLayout['full2'] = <<<'FULL2' +$pageLayout['full_alt'] = <<<'FULL_ALT' @@ -72,7 +72,7 @@ $pageLayout['full2'] = <<<'FULL2' -FULL2; +FULL_ALT; $pageLayout['bare'] = <<<'BARE' @@ -98,12 +98,12 @@ $contentLayout['login'] = <<<'LOGIN'  
  • - +
  • - +
  • @@ -111,7 +111,7 @@ $contentLayout['login'] = <<<'LOGIN'
  • - Inloggegevens verkrijgbaar op aanvraag! + Login credentials available upon request!
  • @@ -121,16 +121,13 @@ LOGIN; $contentLayout['manage']['header'] = <<<'MANAGE_HEADER' - Ingelogd als %1$s --- [EN NL] [Log uit] + Logged in as %1$s --- [EN NL] [Logout] MANAGE_HEADER; @@ -140,9 +137,9 @@ $contentLayout['manage']['section'] = <<<'MANAGE_SECTION' - - - + + + diff --git a/public/lucidAuth.manage.php b/public/lucidAuth.manage.php index 9075744..7488b9d 100644 --- a/public/lucidAuth.manage.php +++ b/public/lucidAuth.manage.php @@ -12,28 +12,26 @@ try { $allUsers = $pdoDB->query(' - SELECT User.Id, User.Username, Role.Rolename, COUNT(DISTINCT SecureToken.Value) AS Sessions + SELECT User.Id, User.Username, Role.Rolename FROM User - LEFT JOIN Role - ON (User.RoleId=Role.Id) - LEFT JOIN SecureToken - ON (User.Id=SecureToken.UserId) + LEFT JOIN Role + ON (Role.Id = User.RoleId) ')->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { // Should really do some actual errorhandling here throw new Exception($e); } - foreach($allUsers as $row) { - $tableRows[] = sprintf('', + $tableRows[] = sprintf('', + $validateTokenResult['uid'] === $row['Id'] ? 'class="currentuser"': null, $row['Id'], explode('\\', $row['Username'])[1], $row['Rolename'], - $row['Sessions'] + '' . ($validateTokenResult['uid'] === $row['Id'] ? null : ' ') ); } - echo sprintf($pageLayout['full2'], + echo sprintf($pageLayout['full_alt'], sprintf($contentLayout['manage']['header'], $validateTokenResult['name'] ), diff --git a/public/misc/script.manage.js b/public/misc/script.manage.js index 1766e5b..ecb4d31 100644 --- a/public/misc/script.manage.js +++ b/public/misc/script.manage.js @@ -2,13 +2,71 @@ $(document).ready(function(){ // Initialize the editable-table functionality $('#usertable').editableTableWidget(); + $('#usertable button.delete').click(function() { + $(this).closest('tr').addClass('removed'); + }); + $('#btnnewuser').click(function() { + // Create a new user; generate pseudo-random username var newUser = 'User' + String(Math.floor(Math.random() * Math.floor(9999))).padStart(4, '0'); - $('#usertable tbody').append($('')); + // Add new user to the interface + // (new `` in `
    UsernameRoleSessionsUsernameRoleManage
    %2$s%3$s%4$s
    %3$s%4$s%5$s
    ' + newUser + 'User0
    `) + $('#usertable tbody').append($('', {class: 'new'}) + .append($('` // To prevent recreating multiple new editors; reference the already existing `` $('#usertable').editableTableWidget({editor: $('#editor')}); + // Add eventhandlers to buttons of newly added `` + $('#usertable .new button.delete').unbind().click(function() { + $(this).closest('tr').remove(); + }); + }); + + $('#btnsave').click(function() { + var newEntries = []; + $('#usertable .new').each(function() { + newEntries.push({ + 'userName': $(this).find('td:nth-child(1)').text(), + 'roleName': $(this).find('td:nth-child(2)').text() + }); + }); + var removedEntries = []; + $('#usertable .removed').each(function() { + removedEntries.push({ + 'userId': $(this).find('td:nth-child(1)').data('userid'), + 'userName': $(this).find('td:nth-child(1)').text(), + 'roleName': $(this).find('td:nth-child(2)').text() + }); + }); + +console.log({'new': newEntries, 'removed': removedEntries}); + +/* $.get("psworker.php", { + do: "mutate", + mutations: { + new: newEntries, + removed: removedEntries + } + })*/ + }); + + $('#btncancel').click(function() { + window.location.reload(); }); if (localStorage.getItem('theme') !== null) { diff --git a/public/misc/script.translation.js b/public/misc/script.translation.js index 1c1de54..9b002cd 100644 --- a/public/misc/script.translation.js +++ b/public/misc/script.translation.js @@ -3,6 +3,7 @@ var locales = { button_new: "new", button_save: "save", button_cancel: "cancel", + button_sessions: "sessions", button_delete: "delete", button_login: "login", heading_error: "ERROR!", @@ -10,12 +11,16 @@ var locales = { label_username: "Username:", link_logout: "Logout", span_credentialsavailable: "Login credentials available upon request!", - span_loggedinas: "Logged in as" + span_loggedinas: "Logged in as", + th_username: "Username", + th_role: "Role", + th_manage: "Manage" }, nl: { button_new: "nieuw", button_save: "opslaan", button_cancel: "annuleren", + button_sessions: "sessies", button_delete: "verwijder", button_login: "log in", heading_error: "FOUT!", @@ -23,7 +28,10 @@ var locales = { label_username: "Gebruikersnaam:", link_logout: "Log uit", span_credentialsavailable: "Inloggegevens verkrijgbaar op aanvraag!", - span_loggedinas: "Ingelogd als" + span_loggedinas: "Ingelogd als", + th_username: "Gebruikersnaam", + th_role: "Rol", + th_manage: "Beheer" } // ... etc. }; @@ -31,7 +39,7 @@ $(document).ready(function(){ $('[id^=linklanguage-]').click(function() { var selectedlang = $(this).attr('id').split('-')[1]; // Replace text of each element with translated value - $('[data-translation]').each(function(index) { + $('[data-translation]').each(function() { $(this).text(locales[selectedlang][$(this).data('translation')]); }); // Enable/disable (toggle) anchors @@ -43,7 +51,7 @@ $(document).ready(function(){ }); if (localStorage.getItem('language') !== null) { - $('[data-translation]').each(function(index) { + $('[data-translation]').each(function() { $(this).text(locales[localStorage.getItem('language')][$(this).data('translation')]); }); $('span#user a.current').removeClass('current'); diff --git a/public/misc/style.css b/public/misc/style.css index 8abf93a..b1dd04a 100644 --- a/public/misc/style.css +++ b/public/misc/style.css @@ -137,6 +137,13 @@ body { padding: 2px; margin: 0; } + .main section table .new { + font-weight: bold; + } + .main section table .removed td:nth-child(-n+2) { + text-decoration: line-through; + color: grey; + } .main section table tbody tr:nth-child(odd) { background-color: rgb(215, 215, 215); } diff --git a/public/misc/style.panes.css b/public/misc/style.panes.css index f060c14..ac9fa89 100644 --- a/public/misc/style.panes.css +++ b/public/misc/style.panes.css @@ -8,7 +8,7 @@ body{ flex-direction: column; } .header { - height: 125px; + height: 100px; background: #FFFFFF; color: #000000; } @@ -36,7 +36,7 @@ body{ } .main section { overflow-y: scroll; - height: calc(100% - 125px); + height: calc(100% - 100px); } .sidebar-first{ width: 25%;
    ', { + text: newUser + })) + .append($('', { + text: 'User' + })) + .append($('', { + class: 'immutable', + html: ' ' + + '' + })) + ); // Call `editableTableWidget()` again to include the newly added `