]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
ui: Utils: refactor userid parsing to Utils
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 2 Jul 2021 13:06:25 +0000 (15:06 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 2 Jul 2021 13:06:26 +0000 (15:06 +0200)
Originally-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Utils.js

index 7f32f0556b8c32d1d3e9c11824ef5c1d9b2b5678..6526ec21fadf581b6f2e7890e5d23adde3321d9c 100644 (file)
@@ -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 || {};