From: Thomas Lamprecht Date: Fri, 2 Jul 2021 13:06:25 +0000 (+0200) Subject: ui: Utils: refactor userid parsing to Utils X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=e722f108aa0d9f88230e3a351d91a6bd286539f6;p=proxmox-widget-toolkit.git ui: Utils: refactor userid parsing to Utils Originally-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- 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 || {};