2019-01-30 14:14:20 +00:00
|
|
|
Ext.define('PBS.LoginView', {
|
|
|
|
extend: 'Ext.container.Container',
|
|
|
|
xtype: 'loginview',
|
|
|
|
|
|
|
|
controller: {
|
|
|
|
xclass: 'Ext.app.ViewController',
|
|
|
|
|
|
|
|
submitForm: function() {
|
|
|
|
var me = this;
|
|
|
|
var view = me.getView();
|
|
|
|
var loginForm = me.lookupReference('loginForm');
|
2020-04-09 11:37:14 +00:00
|
|
|
var unField = me.lookupReference('usernameField');
|
|
|
|
var saveunField = me.lookupReference('saveunField');
|
2019-01-30 14:14:20 +00:00
|
|
|
|
2020-04-09 11:37:14 +00:00
|
|
|
if (!loginForm.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = loginForm.getValues();
|
|
|
|
|
|
|
|
params.username = params.username + '@' + params.realm;
|
|
|
|
delete(params.realm);
|
|
|
|
|
|
|
|
if (loginForm.isVisible()) {
|
|
|
|
loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
|
2019-01-30 14:14:20 +00:00
|
|
|
}
|
2020-04-09 11:37:14 +00:00
|
|
|
|
|
|
|
// set or clear username
|
|
|
|
var sp = Ext.state.Manager.getProvider();
|
|
|
|
if (saveunField.getValue() === true) {
|
|
|
|
sp.set(unField.getStateId(), unField.getValue());
|
|
|
|
} else {
|
|
|
|
sp.clear(unField.getStateId());
|
|
|
|
}
|
|
|
|
sp.set(saveunField.getStateId(), saveunField.getValue());
|
|
|
|
|
|
|
|
Proxmox.Utils.API2Request({
|
|
|
|
url: '/api2/extjs/access/ticket',
|
|
|
|
params: params,
|
|
|
|
method: 'POST',
|
|
|
|
success: function(resp, opts) {
|
|
|
|
// save login data and create cookie
|
|
|
|
PBS.Utils.updateLoginData(resp.result.data);
|
|
|
|
PBS.app.changeView('mainview');
|
|
|
|
},
|
|
|
|
failure: function(resp, opts) {
|
|
|
|
Proxmox.Utils.authClear();
|
|
|
|
loginForm.unmask();
|
|
|
|
Ext.MessageBox.alert(
|
|
|
|
gettext('Error'),
|
|
|
|
gettext('Login failed. Please try again')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-01-30 14:14:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
control: {
|
2020-04-09 11:37:14 +00:00
|
|
|
'field[name=username]': {
|
|
|
|
specialkey: function(f, e) {
|
|
|
|
if (e.getKey() === e.ENTER) {
|
|
|
|
var pf = this.lookupReference('passwordField');
|
|
|
|
if (!pf.getValue()) {
|
|
|
|
pf.focus(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'field[name=lang]': {
|
|
|
|
change: function(f, value) {
|
|
|
|
var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
|
|
|
|
Ext.util.Cookies.set('PBSLangCookie', value, dt);
|
|
|
|
this.getView().mask(gettext('Please wait...'), 'x-mask-loading');
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
},
|
2019-01-30 14:14:20 +00:00
|
|
|
'button[reference=loginButton]': {
|
|
|
|
click: 'submitForm'
|
2020-04-09 11:37:14 +00:00
|
|
|
},
|
|
|
|
'window[reference=loginwindow]': {
|
|
|
|
show: function() {
|
|
|
|
var sp = Ext.state.Manager.getProvider();
|
|
|
|
var checkboxField = this.lookupReference('saveunField');
|
|
|
|
var unField = this.lookupReference('usernameField');
|
|
|
|
|
|
|
|
var checked = sp.get(checkboxField.getStateId());
|
|
|
|
checkboxField.setValue(checked);
|
|
|
|
|
|
|
|
if(checked === true) {
|
|
|
|
var username = sp.get(unField.getStateId());
|
|
|
|
unField.setValue(username);
|
|
|
|
var pwField = this.lookupReference('passwordField');
|
|
|
|
pwField.focus();
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 14:14:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: 'viewport',
|
|
|
|
|
|
|
|
layout: {
|
|
|
|
type: 'border'
|
|
|
|
},
|
|
|
|
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
region: 'north',
|
|
|
|
xtype: 'container',
|
|
|
|
layout: {
|
|
|
|
type: 'hbox',
|
|
|
|
align: 'middle'
|
|
|
|
},
|
|
|
|
margin: '2 5 2 5',
|
|
|
|
height: 38,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
xtype: 'proxmoxlogo'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'versioninfo',
|
|
|
|
makeApiCall: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
region: 'center'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'window',
|
|
|
|
closable: false,
|
|
|
|
resizable: false,
|
|
|
|
reference: 'loginwindow',
|
|
|
|
autoShow: true,
|
|
|
|
modal: true,
|
2020-04-09 11:37:14 +00:00
|
|
|
width: 400,
|
2019-01-30 14:14:20 +00:00
|
|
|
|
2020-04-09 11:37:14 +00:00
|
|
|
defaultFocus: 'usernameField',
|
2019-01-30 14:14:20 +00:00
|
|
|
|
|
|
|
layout: {
|
|
|
|
type: 'auto'
|
|
|
|
},
|
|
|
|
|
|
|
|
title: gettext('Proxmox Backup Server Login'),
|
|
|
|
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
xtype: 'form',
|
|
|
|
layout: {
|
|
|
|
type: 'form'
|
|
|
|
},
|
|
|
|
defaultButton: 'loginButton',
|
|
|
|
url: '/api2/extjs/access/ticket',
|
|
|
|
reference: 'loginForm',
|
|
|
|
|
|
|
|
fieldDefaults: {
|
|
|
|
labelAlign: 'right',
|
|
|
|
allowBlank: false
|
|
|
|
},
|
|
|
|
|
|
|
|
items: [
|
2020-04-09 11:37:14 +00:00
|
|
|
{
|
|
|
|
xtype: 'pbsRealmComboBox',
|
|
|
|
name: 'realm'
|
|
|
|
},
|
2019-01-30 14:14:20 +00:00
|
|
|
{
|
|
|
|
xtype: 'textfield',
|
|
|
|
fieldLabel: gettext('User name'),
|
|
|
|
name: 'username',
|
|
|
|
itemId: 'usernameField',
|
2020-04-09 11:37:14 +00:00
|
|
|
reference: 'usernameField',
|
|
|
|
stateId: 'login-username'
|
2019-01-30 14:14:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'textfield',
|
|
|
|
inputType: 'password',
|
|
|
|
fieldLabel: gettext('Password'),
|
|
|
|
name: 'password',
|
2019-12-17 10:35:13 +00:00
|
|
|
itemId: 'passwordField',
|
|
|
|
reference: 'passwordField',
|
2020-04-09 11:37:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'proxmoxLanguageSelector',
|
|
|
|
fieldLabel: gettext('Language'),
|
|
|
|
value: Ext.util.Cookies.get('PBSLangCookie') || Proxmox.defaultLang || 'en',
|
|
|
|
name: 'lang',
|
|
|
|
reference: 'langField',
|
|
|
|
submitValue: false
|
2019-01-30 14:14:20 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
buttons: [
|
2020-04-09 11:37:14 +00:00
|
|
|
{
|
|
|
|
xtype: 'checkbox',
|
|
|
|
fieldLabel: gettext('Save User name'),
|
|
|
|
name: 'saveusername',
|
|
|
|
reference: 'saveunField',
|
|
|
|
stateId: 'login-saveusername',
|
|
|
|
labelWidth: 250,
|
|
|
|
labelAlign: 'right',
|
|
|
|
submitValue: false
|
|
|
|
},
|
2019-01-30 14:14:20 +00:00
|
|
|
{
|
|
|
|
text: gettext('Login'),
|
|
|
|
reference: 'loginButton',
|
|
|
|
formBind: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|