ui: login: cleanups, mostly openID related
similar to what was done in PVE. - factor out openid_login_param to widget-toolkit as getOpenIDRedirectionAuthorization and use it - use camel case to match our JS style guide and our framework (and basically the rest of the JS world) - minor cleanups like moving variable definition into the single if branch their used Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
1ce1a5e5cc
commit
e1d85f1840
|
@ -30,18 +30,16 @@ Ext.define('PBS.LoginView', {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let redirect_url = location.origin;
|
let creds = loginForm.getValues();
|
||||||
|
|
||||||
let params = loginForm.getValues();
|
|
||||||
|
|
||||||
if (this.getViewModel().data.openid === true) {
|
if (this.getViewModel().data.openid === true) {
|
||||||
let realm = params.realm;
|
const redirectURL = location.origin;
|
||||||
try {
|
try {
|
||||||
let resp = await PBS.Async.api2({
|
let resp = await PBS.Async.api2({
|
||||||
url: '/api2/extjs/access/openid/auth-url',
|
url: '/api2/extjs/access/openid/auth-url',
|
||||||
params: {
|
params: {
|
||||||
realm: realm,
|
realm: creds.realm,
|
||||||
"redirect-url": redirect_url,
|
"redirect-url": redirectURL,
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
|
@ -57,8 +55,8 @@ Ext.define('PBS.LoginView', {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
params.username = params.username + '@' + params.realm;
|
creds.username = `${creds.username}@${creds.realm}`;
|
||||||
delete params.realm;
|
delete creds.realm;
|
||||||
|
|
||||||
if (loginForm.isVisible()) {
|
if (loginForm.isVisible()) {
|
||||||
loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
|
loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
|
||||||
|
@ -76,7 +74,7 @@ Ext.define('PBS.LoginView', {
|
||||||
try {
|
try {
|
||||||
let resp = await PBS.Async.api2({
|
let resp = await PBS.Async.api2({
|
||||||
url: '/api2/extjs/access/ticket',
|
url: '/api2/extjs/access/ticket',
|
||||||
params: params,
|
params: creds,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -165,21 +163,22 @@ Ext.define('PBS.LoginView', {
|
||||||
pwField.focus();
|
pwField.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
let param = PBS.Utils.openid_login_param();
|
let auth = Proxmox.Utils.getOpenIDRedirectionAuthorization();
|
||||||
if (param !== undefined) {
|
if (auth !== undefined) {
|
||||||
Proxmox.Utils.authClear();
|
Proxmox.Utils.authClear();
|
||||||
|
|
||||||
let loginForm = this.lookupReference('loginForm');
|
let loginForm = this.lookupReference('loginForm');
|
||||||
loginForm.mask(gettext('OpenID login - please wait...'), 'x-mask-loading');
|
loginForm.mask(gettext('OpenID login - please wait...'), 'x-mask-loading');
|
||||||
|
|
||||||
let redirect_url = location.origin;
|
// openID checks the original redirection URL we used, so pass that too
|
||||||
|
const redirectURL = location.origin;
|
||||||
|
|
||||||
Proxmox.Utils.API2Request({
|
Proxmox.Utils.API2Request({
|
||||||
url: '/api2/extjs/access/openid/login',
|
url: '/api2/extjs/access/openid/login',
|
||||||
params: {
|
params: {
|
||||||
state: param.state,
|
state: auth.state,
|
||||||
code: param.code,
|
code: auth.code,
|
||||||
"redirect-url": redirect_url,
|
"redirect-url": redirectURL,
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
failure: function(response) {
|
failure: function(response) {
|
||||||
|
@ -193,10 +192,10 @@ Ext.define('PBS.LoginView', {
|
||||||
},
|
},
|
||||||
success: function(response, options) {
|
success: function(response, options) {
|
||||||
loginForm.unmask();
|
loginForm.unmask();
|
||||||
let data = response.result.data;
|
let creds = response.result.data;
|
||||||
PBS.Utils.updateLoginData(data);
|
PBS.Utils.updateLoginData(creds);
|
||||||
PBS.app.changeView('mainview');
|
PBS.app.changeView('mainview');
|
||||||
history.replaceState(null, '', redirect_url + '#pbsDashboard');
|
history.replaceState(null, '', `${redirectURL}#pbsDashboard`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,14 +326,6 @@ Ext.define('PBS.Utils', {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
openid_login_param: function() {
|
|
||||||
let param = Ext.Object.fromQueryString(window.location.search);
|
|
||||||
if (param.state !== undefined && param.code !== undefined) {
|
|
||||||
return param;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
|
|
||||||
calculate_dedup_factor: function(gcstatus) {
|
calculate_dedup_factor: function(gcstatus) {
|
||||||
let dedup = 1.0;
|
let dedup = 1.0;
|
||||||
if (gcstatus['disk-bytes'] > 0) {
|
if (gcstatus['disk-bytes'] > 0) {
|
||||||
|
|
Loading…
Reference in New Issue