#3806 Supplant fixes
gitea/hedera-web/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2022-05-09 15:52:29 +02:00
parent 7e398059dc
commit 4bb31e9dd3
10 changed files with 60 additions and 10 deletions

View File

@ -50,7 +50,7 @@
<htk-text form="iter" column="value7"/> <htk-text form="iter" column="value7"/>
</p> </p>
<p> <p>
@<htk-text form="iter" column="id"/> #<htk-text form="iter" column="id"/>
</p> </p>
<p> <p>
<htk-text form="iter" column="image"/> <htk-text form="iter" column="image"/>

View File

@ -50,7 +50,7 @@
<htk-text form="iter" column="nickname"/> <htk-text form="iter" column="nickname"/>
</p> </p>
<p> <p>
@<htk-text form="iter" column="id"/> - #<htk-text form="iter" column="id"/> -
<htk-text form="iter" column="name"/> <htk-text form="iter" column="name"/>
</p> </p>
<div class="clear"/> <div class="clear"/>

View File

@ -406,7 +406,7 @@
<htk-text form="card" column="subName"/> <htk-text form="card" column="subName"/>
</p> </p>
<p> <p>
@<htk-text form="card" column="id"/> #<htk-text form="card" column="id"/>
</p> </p>
<p> <p>
<htk-text form="card" column="stems" format="_%.0d Units"/> <htk-text form="card" column="stems" format="_%.0d Units"/>

View File

@ -56,7 +56,7 @@
<htk-text form="iter" column="landed" format="%D"/> <htk-text form="iter" column="landed" format="%D"/>
</p> </p>
<p> <p>
@<htk-text form="iter" column="id"/> #<htk-text form="iter" column="id"/>
</p> </p>
<p> <p>
<htk-text form="iter" column="nickname"/> <htk-text form="iter" column="nickname"/>

View File

@ -27,7 +27,7 @@
<htk-loader class="head" form="ticket"> <htk-loader class="head" form="ticket">
<div> <div>
<p class="important ticket-id"> <p class="important ticket-id">
@<htk-text column="id" form="ticket"/> #<htk-text column="id" form="ticket"/>
</p> </p>
<p> <p>
<t>Preparation</t> <htk-text form="ticket" column="shipped" format="%D"/> <t>Preparation</t> <htk-text form="ticket" column="shipped" format="%D"/>
@ -151,7 +151,7 @@
<htk-text form="iter" column="name"/> <htk-text form="iter" column="name"/>
</h2> </h2>
<p> <p>
@<htk-text form="iter" column="id"/> #<htk-text form="iter" column="id"/>
</p> </p>
<p class="amount"> <p class="amount">
<htk-text form="iter" column="quantity"/> <htk-text form="iter" column="quantity"/>

View File

@ -128,6 +128,7 @@ module.exports = new Class({
* Ends the user supplanting and restores the last login. * Ends the user supplanting and restores the last login.
**/ **/
,supplantEnd: function() { ,supplantEnd: function() {
this.lbSend('POST', 'Accounts/logout');
this.fetchToken(); this.fetchToken();
} }

View File

@ -8,7 +8,7 @@
</vn-group> </vn-group>
<div id="report" class="sheet"> <div id="report" class="sheet">
<h2> <h2>
@<htk-text column="id" form="ticket"/> #<htk-text column="id" form="ticket"/>
</h2> </h2>
<div class="header"> <div class="header">
<div> <div>

View File

@ -2,6 +2,8 @@
namespace Vn\Web; namespace Vn\Web;
include __DIR__.'/uid.php';
use Vn\Db; use Vn\Db;
use Vn\Lib\Locale; use Vn\Lib\Locale;
use Vn\Lib\UserException; use Vn\Lib\UserException;
@ -223,15 +225,45 @@ abstract class Service {
return $userDb; 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. * Generates a JWT authentication token for the specified $user.
* *
* @param {string} $user The user name * @param {string} $user The user name
* @param {boolean} $remember Wether to create long live token * @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 * @return {string} The JWT generated token
*/ */
function createToken($user, $remember = FALSE) { function createJwtToken($user, $remember = FALSE) {
if ($remember) if ($remember)
$tokenLife = WEEK; $tokenLife = WEEK;
else else

14
web/uid.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace Vn\Web;
const DEFAULT_TOKEN_LEN = 64;
const UIDCHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
function uid($length) {
$bytes = bin2hex(random_bytes($length));
$r = '';
for ($i = 0; $i < $length; $i++)
$r .= UIDCHARS[hexdec(substr($bytes, $i * 2, 2)) % 64];
return $r;
}

View File

@ -82,7 +82,10 @@ var devConfig = {
stats: { chunks: false }, stats: { chunks: false },
proxy: { proxy: {
'/api': 'http://localhost:3000', '/api': 'http://localhost:3000',
'/': 'http://localhost/projects/hedera-web' '/': {
target: 'http://localhost/projects/hedera-web',
bypass: (req) => req.path !== '/' ? req.path : null
}
} }
}, },
devtool: 'eval' devtool: 'eval'