From e722f108aa0d9f88230e3a351d91a6bd286539f6 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 2 Jul 2021 15:06:25 +0200 Subject: [PATCH] ui: Utils: refactor userid parsing to Utils Originally-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- src/Utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Utils.js b/src/Utils.js index 7f32f05..6526ec2 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -238,6 +238,30 @@ utilities: { return min < width ? width : min; }, + // returns username + realm + parse_userid: function(userid) { + if (!Ext.isString(userid)) { + return [undefined, undefined]; + } + + let match = userid.match(/^(.+)@([^@]+)$/); + if (match !== null) { + return [match[1], match[2]]; + } + + return [undefined, undefined]; + }, + + render_username: function(userid) { + let username = PVE.Utils.parse_userid(userid)[0] || ""; + return Ext.htmlEncode(username); + }, + + render_realm: function(userid) { + let username = PVE.Utils.parse_userid(userid)[1] || ""; + return Ext.htmlEncode(username); + }, + getStoredAuth: function() { let storedAuth = JSON.parse(window.localStorage.getItem('ProxmoxUser')); return storedAuth || {}; -- 2.39.2