diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-05 04:07:05 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-05-05 04:07:05 +0300 |
| commit | 537673748f0b01539fc5839c2af1bacbefafc86d (patch) | |
| tree | c2032ff9efb06257bbf70f3329524d86bc2cb6e3 /public/assets/js | |
| parent | 63f714d5a78b765c117ebf6bbdfdbd748dd45644 (diff) | |
| download | gyraf1gov-537673748f0b01539fc5839c2af1bacbefafc86d.tar.gz gyraf1gov-537673748f0b01539fc5839c2af1bacbefafc86d.tar.bz2 gyraf1gov-537673748f0b01539fc5839c2af1bacbefafc86d.zip | |
the penalty form (input, new record)
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/cookie.js | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/public/assets/js/cookie.js b/public/assets/js/cookie.js index fcd3006..ab51c05 100644 --- a/public/assets/js/cookie.js +++ b/public/assets/js/cookie.js @@ -21,7 +21,10 @@ function createCookie(name, value, expire) { expires = ""; } - document.cookie = name+"="+value+expires+"; path=/"; + // encode cookie + let enc = encodeRFC3986URIComponent(value); + + document.cookie = name +"="+ enc + expires +"; path=/; SameSite=Strict"; } @@ -41,7 +44,7 @@ function readCookie(name) { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) == 0) { - return c.substring(nameEQ.length,c.length); + return decodeURIComponent(c.substring(nameEQ.length,c.length)); } } return null; @@ -76,3 +79,37 @@ function cookieExists(name) { } return false; } + + +/** encodeRFC3986URIComponent + * + * RFC3986 compatible URI encoding + * + * @param str + * @returns (string) RCF3986 compatible encoded str + */ +function encodeRFC3986URIComponent(str) { + return encodeURIComponent(str).replace( + /[!'()*]/g, + (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`, + ); +} + + +/** example: + * --- -- -- - - - + * + * read connection cookie (as json object) + * + * connection = JSON.parse(decodeURIComponent(readCookie('con'))) + * + * then... + * connection = { + * rid: `role-id`, + * name: `full name` of connected user + * } + * + * so to refer to user's name ... + * console.log(connection.name) + * + */
\ No newline at end of file |
