From 4bb31e9dd3fba3bca3498022c599c14b0e1882ab Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 9 May 2022 15:52:29 +0200 Subject: [PATCH] #3806 Supplant fixes --- forms/admin/items/ui.xml | 2 +- forms/admin/users/ui.xml | 2 +- forms/ecomerce/catalog/ui.xml | 2 +- forms/ecomerce/orders/ui.xml | 2 +- forms/ecomerce/ticket/ui.xml | 4 ++-- js/vn/json-connection.js | 1 + reports/delivery-note/ui.xml | 2 +- web/service.php | 36 +++++++++++++++++++++++++++++++++-- web/uid.php | 14 ++++++++++++++ webpack.config.js | 5 ++++- 10 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 web/uid.php diff --git a/forms/admin/items/ui.xml b/forms/admin/items/ui.xml index acd3aba4..41fbf780 100644 --- a/forms/admin/items/ui.xml +++ b/forms/admin/items/ui.xml @@ -50,7 +50,7 @@

- @ + #

diff --git a/forms/admin/users/ui.xml b/forms/admin/users/ui.xml index 088cac9d..0b41e395 100644 --- a/forms/admin/users/ui.xml +++ b/forms/admin/users/ui.xml @@ -50,7 +50,7 @@

- @ - + # -

diff --git a/forms/ecomerce/catalog/ui.xml b/forms/ecomerce/catalog/ui.xml index f6780139..d7ea6de6 100644 --- a/forms/ecomerce/catalog/ui.xml +++ b/forms/ecomerce/catalog/ui.xml @@ -406,7 +406,7 @@

- @ + #

diff --git a/forms/ecomerce/orders/ui.xml b/forms/ecomerce/orders/ui.xml index b035a2fd..e64c70e0 100644 --- a/forms/ecomerce/orders/ui.xml +++ b/forms/ecomerce/orders/ui.xml @@ -56,7 +56,7 @@

- @ + #

diff --git a/forms/ecomerce/ticket/ui.xml b/forms/ecomerce/ticket/ui.xml index 0901920f..c14ff6fa 100644 --- a/forms/ecomerce/ticket/ui.xml +++ b/forms/ecomerce/ticket/ui.xml @@ -27,7 +27,7 @@

- @ + #

Preparation @@ -151,7 +151,7 @@

- @ + #

diff --git a/js/vn/json-connection.js b/js/vn/json-connection.js index 40939699..7e981ad7 100644 --- a/js/vn/json-connection.js +++ b/js/vn/json-connection.js @@ -128,6 +128,7 @@ module.exports = new Class({ * Ends the user supplanting and restores the last login. **/ ,supplantEnd: function() { + this.lbSend('POST', 'Accounts/logout'); this.fetchToken(); } diff --git a/reports/delivery-note/ui.xml b/reports/delivery-note/ui.xml index 452bb5e4..23f95654 100644 --- a/reports/delivery-note/ui.xml +++ b/reports/delivery-note/ui.xml @@ -8,7 +8,7 @@

- @ + #

diff --git a/web/service.php b/web/service.php index abaa439b..34e9b5ef 100644 --- a/web/service.php +++ b/web/service.php @@ -2,6 +2,8 @@ namespace Vn\Web; +include __DIR__.'/uid.php'; + use Vn\Db; use Vn\Lib\Locale; use Vn\Lib\UserException; @@ -223,15 +225,45 @@ abstract class Service { return $userDb; } + /** + * Generates a authentication token for the specified $user. + * + * @param {string} $user The user name + * @param {boolean} $remember Wether to create long live token + * @return {string} The generated token + */ + function createToken($user, $remember = FALSE) { + if ($remember) + $tokenLife = 2 * WEEK; + else + $tokenLife = 30 * MIN; + + $token = uid(DEFAULT_TOKEN_LEN); + $userId = $this->db->getValue( + 'SELECT id FROM account.user WHERE `name` = #', + [$user] + ); + + $this->db->query( + 'INSERT INTO salix.AccessToken + SET id = #, + ttl = #, + created = NOW(), + userId = #', + [$token, $tokenLife, $userId] + ); + + return $token; + } + /** * Generates a JWT authentication token for the specified $user. * * @param {string} $user The user name * @param {boolean} $remember Wether to create long live token - * @param {boolean} $recover Wether to enable recovery mode on login * @return {string} The JWT generated token */ - function createToken($user, $remember = FALSE) { + function createJwtToken($user, $remember = FALSE) { if ($remember) $tokenLife = WEEK; else diff --git a/web/uid.php b/web/uid.php new file mode 100644 index 00000000..46cf85a3 --- /dev/null +++ b/web/uid.php @@ -0,0 +1,14 @@ + req.path !== '/' ? req.path : null + } } }, devtool: 'eval'