From 4bc1cbd8b339d08ccba6898e867636a1bdc2316d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 29 Apr 2017 18:34:27 +0200 Subject: [PATCH] js/LoginView.js: implement autologin with quarantine tickets --- js/LoginView.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/js/LoginView.js b/js/LoginView.js index cf8d6cc..0ecd617 100644 --- a/js/LoginView.js +++ b/js/LoginView.js @@ -4,6 +4,43 @@ Ext.define('PMG.LoginView', { controller: { xclass: 'Ext.app.ViewController', + + init: function(view) { + var loginForm = this.lookupReference('loginForm'); + + // try autologin with quarantine ticket from URL + + var qs = Ext.Object.fromQueryString(location.search); + if (qs.ticket == undefined) { return; } + var ticket = decodeURIComponent(qs.ticket); + var match = ticket.match(/^PMGQUAR:([^\s\:]+):/); + if (!match) { return; } + var username = match[1]; + + Proxmox.Utils.API2Request({ + url: '/api2/extjs/access/ticket', + params: { + username: username, + password: ticket + }, + method: 'POST', + success: function(response) { + // save login data and create cookie + PMG.Utils.updateLoginData(response.result.data); + // change view to mainview + view.destroy(); + Ext.create({ xtype: 'mainview' }); + }, + failure: function(form, action) { + loginForm.unmask(); + Ext.MessageBox.alert( + gettext('Error'), + gettext('Login failed. Please try again') + ); + } + }); + }, + submitForm: function() { var me = this; var loginForm = me.lookupReference('loginForm');