var smartphone = "N"; try { if (navigator.userAgent.toLowerCase().indexOf("iphone")!=-1 || navigator.userAgent.toLowerCase().indexOf("android")!=-1) smartphone = "Y"; console.log("navigator.platform: "+navigator.platform+"\nnavigator.userAgent: "+navigator.userAgent+"\nnavigator.appName: "+navigator.appName+"\nnavigator.product: "+navigator.product); } catch (e) {} Ext.onReady(function(){ Ext.QuickTips.init(); var applicationId = parameters['applicationId'] == null ? '' : parameters['applicationId']; var title = parameters['appTitle'] == null ? '' : parameters['appTitle']; var ts = ''; var restfulToken = ''; var authToken = ''; var items = []; Ext.override(Ext.form.ComboBox, { setValue : function(v){ if(this.store.totalLength === undefined && ((this.mode == 'local' && this.getStore().url != null)||(this.mode == 'remote'))){ this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true}); if(this.store.lastOptions === null){ this.store.load(); } return; } var text = v; if(this.valueField){ var r = this.findRecord(this.valueField, v); if(r){ text = r.data[this.displayField]; }else if(this.valueNotFoundText !== undefined){ text = this.valueNotFoundText; } } this.lastSelectionText = text; if(this.hiddenField){ this.hiddenField.value = v; } Ext.form.ComboBox.superclass.setValue.call(this, text); this.value = v; } }); var langsDataStore = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/platform/loginlanguages?appId='+applicationId, method: 'GET' }), reader: new Ext.data.JsonReader({ root: 'valueObjectList', totalProperty: 'resultSetLength' }, [ {name: 'pk.languageId'} , {name: 'description'} , {name: 'languageIndex', type: 'float', useNull: true} , {name: 'rowVersion', type: 'int'} , {name: 'userIdCreate'} , {name: 'createDate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'} , {name: 'userIdUpdate'} , {name: 'lastUpdate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'} , {name: 'status'} , {name: 'languageIdApp'} , {name: 'languageIdPermissions'} , {name: 'defaultLanguage'} ]), sortInfo: {field: 'languageId', direction: 'ASC'}, remoteSort:true, batch: true, autoSave: false }); //langsDataStore.sortInfo = {field: 'languageIdApp', direction: 'ASC'}; var langOfBrowser = parameters['translateLabelsOfBrowserLanguage'] == 'Y' ? ((isIE ? (navigator.browserLanguage != null ? navigator.browserLanguage : navigator.language) : navigator.language).toUpperCase().substring(0, 2) == 'IT' ? 'IT' : 'EN') : 'EN'; parameters['langOfBrowser'] = langOfBrowser; if(parameters['comboOfCompanySite'] == 'Y') { var companyDS = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/platform/getApplications/getCompaniesList', method: 'GET' }), reader: new Ext.data.JsonReader({ root: 'valueObjectList', totalProperty: 'resultSetLength' }, [ {name: 'pk_companyId'}, , {name: 'corporateName1'} ]), remoteSort:true, batch: true, autoSave: false }); companyDS.addListener("load",function(store, records, options) { var combo = login.getComponent('companyId'); if (combo != null && combo.getValue() != null && combo.getValue() != '') { siteIdsDS.load(); } if(companyDS.getCount() == 1) { var record = companyDS.getAt(0); combo.setValue(records[0].data.pk_companyId); //corporateName1); siteIdsDS.load(); } }); items.push( { xtype: 'combo', typeAhead: true, fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? "Societ\u00E0" : 'Company Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'companyId', itemId:'companyId', id:'companyId', triggerAction: 'all', lazyRender: false, width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, mode: 'remote', store: companyDS, valueField: 'pk_companyId', hiddenName:'companyId', displayField: 'corporateName1', autoSelect: true, forceSelection: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? "Societ\u00E0" : 'Company Id') : '', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '', hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false, listeners: { select: function(combo, record, index) { siteIdsDS.baseParams.companyId = login.getComponent("companyId") != null ? login.getComponent("companyId").getValue() : null; siteIdsDS.load(); }, change: function(combo, newValue, oldValue) { if(newValue == null || newValue == '') { var combo = login.getComponent('siteId'); combo.setValue(null); siteIdsDS.baseParams.companyId = -1; siteIdsDS.load(); } } } }); var siteIdsDS = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/platform/getApplications/getSiteIdsList', method: 'GET' }), reader: new Ext.data.JsonReader({ root: 'valueObjectList', totalProperty: 'resultSetLength' }, [ {name: 'pk_siteId', type: 'int'}, {name: 'description'} ]), sortInfo: {field: 'pk.siteId', direction: 'ASC'}, remoteSort:true, batch: true, autoSave: false }); siteIdsDS.addListener("load",function(store, records, options) { var combo = login.getComponent('siteId'); if (combo != null && combo.getValue() != null && combo.getValue() != '') { combo.validate(); return; } if (siteIdsDS.getCount() < 1) { combo.setValue(null); } else if (siteIdsDS.getCount() == 1) { var record = siteIdsDS.getAt(0); combo.setValue(records[0].data.pk_siteId); //combo.validateValue(records[0].data.description); } }); items.push( { xtype: 'combo', typeAhead: true, fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Sito' : 'Site Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'siteId', itemId:'siteId', id:'siteId', triggerAction: 'all', lazyRender: false, width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, mode: 'remote', store: siteIdsDS, valueField: 'pk_siteId', hiddenName:'siteId', displayField: 'description', autoSelect: true, forceSelection: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Sito' : 'Site Id') : '', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '', hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false, listeners: { beforequery : function(qe) { var combo = qe.combo; if(login.getComponent("companyId") != null) { combo.store.baseParams.companyId = login.getComponent("companyId").getValue(); } delete combo.lastQuery; } } }); } else { items.push({ xtype: 'textfield', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Società' : 'Company Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'companyId', itemId:'companyId', id:'companyId', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, enableKeyEvents: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Società' : 'Company Id') : '', value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '', hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false, listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doSubmit(); } } }); items.push({ xtype: 'textfield', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'siteId', itemId:'siteId', id:'siteId', width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, enableKeyEvents: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id') : '', value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '', hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false, listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doSubmit(); } } }); } items.push({ xtype: 'textfield', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Utente' : 'Username'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'username', itemId:'username', id:'username', width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, allowBlank:false, enableKeyEvents: true, value: valHideControls['username'] != null ? valHideControls['username'] : '', emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Utente' : 'Username') : '', listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doSubmit(); } } }); items.push({ xtype: 'textfield', autocomplete: "false", fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Password' : 'Password'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'password', itemId:'password', id:'passwordId', inputType:'password', width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, enableKeyEvents: true, allowBlank:false, value: valHideControls['password'] != null ? valHideControls['password'] : '', emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Password' : 'Password') : '', listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doSubmit(); } } }); window.pwdSwitch = function(comp) { if (comp.showPwd==null || comp.showPwd==false) { comp.showPwd = true; comp.src = "../images/nascondi.svg"; var pwd = document.getElementById("passwordId"); pwd.type="text"; } else { comp.showPwd = false; comp.src = "../images/mostra.svg"; var pwd = document.getElementById("passwordId"); pwd.type="password"; } } items.push({ xtype: 'label', id: 'pwdImg', html: '', listeners: { render: function(comp) { setTimeout(function() { var pwd = document.getElementById("passwordId"); var pwdImg = document.getElementById("pwdImg"); pwdImg.style= "width:20px; height:20px; position: absolute; top: "+(pwd.parentNode.offsetTop+5)+"px; left: "+(pwd.offsetWidth+pwd.offsetLeft-30)+"px"; },500); } } }); if(hideControls['language'] == null || !hideControls['language']) { var hiddenLanguageIdField = new Ext.form.Hidden({ itemId: 'languageId', name: 'languageId' }); items.push(hiddenLanguageIdField); if(valHideControls['languageId']!=null && valHideControls['languageId'] != '') hiddenLanguageIdField.setValue(valHideControls['languageId']); items.push({ fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Lingua' : 'Language'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, itemId: 'language', xtype: 'combo', typeAhead: true, name: 'language', id: 'language', triggerAction: 'all', lazyRender: false, width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth, mode: 'remote', store: langsDataStore, valueField: 'pk.languageId', emptyText : (parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Lingua ' : 'Language ') : '') + (langOfBrowser == 'IT' ? '-default utente-' : '-user default-'), displayField: 'description', autoSelect: true, forceSelection: true, value: valHideControls['languageId']!=null ? valHideControls['languageId'] : '', listeners: { "select" : function(combo, record, index) { hiddenLanguageIdField.setValue(record.get("pk.languageId")); }, "change" : function(combo, newValue, oldValue ) { // +MC 06/02/2015: this is needed, since if the user cleans up the language (no language set, i.e. default language), // the "select" event would not be invoked. Cleaning up the combo would still invoke "change" event! hiddenLanguageIdField.setValue(newValue); } } }); } var showOtp = 'N'; var authToKenMail = 'N'; items.push({ fieldLabel: '', labelSeparator: '', boxLabel: (langOfBrowser == 'IT' ? 'Ricordami' : 'Save account'), itemId: 'saveAccount', name: 'saveAccount', id: 'saveAccount' }); var buttonsBar = new Ext.Panel({ baseCls: 'x-plain', layout: 'absolute', height: 40, width: '100%', items: [ ] }); var loginW = 75; var loginS = null; if (parameters['authBoxes']!=null && parameters['authBoxes'].indexOf('AUTH_BOX_GOOGLE')!=-1) { loginW = 200; loginS = { width: '200px !important' }; } if (parameters['loginVersion'] == null || parameters['loginVersion'] == '' || parameters['loginVersion'] == '1') { buttonsBar.add(new Ext.Button({ x: 1, y:10, text: (langOfBrowser == 'IT' ? 'Accedi' : 'Login'), width: loginW, style: loginS, cls: 'loginButton', handler: function() { doSubmit(); } }) ); if(hideControls['exit'] == null || !hideControls['exit']) { buttonsBar.add( new Ext.Button({ x: 200, y: 10, text: (langOfBrowser == 'IT' ? 'Esci' : 'Exit'), width: 75, handler: function() { var redirect = '/platform/'; window.location = redirect; } }) ); } } else if(parameters['loginVersion'] != null && parameters['loginVersion'] == '2') { if(hideControls['exit'] == null || !hideControls['exit']) { buttonsBar.add( new Ext.Button({ x: 115, y: 10, text: (langOfBrowser == 'IT' ? 'Esci' : 'Exit'), width: 75, handler: function() { var redirect = '/platform'; window.location = redirect; } }) ); } buttonsBar.add(new Ext.Button({ x: 200, y:10, text: (langOfBrowser == 'IT' ? 'Accedi' : 'Login'), width: loginW, style: loginS, cls: 'loginButton', handler: function() { doSubmit(); } }) ); } items.push(buttonsBar); items.push({ id: 'forgotpwd', xtype: 'component', hidden: hideControls['forgotpwd'] != null ? hideControls['forgotpwd'] : false, autoEl: { tag: 'div', id: 'forgotpwdDiv', //className: 'forgotpwd', html: (langOfBrowser == 'IT' ? 'Password Dimenticata?' : 'Forgot Password?') } }); items.push({ id: 'additionalLink', xtype: 'component', hidden: hideControls['additionalLink'] != null ? hideControls['additionalLink'] : false, autoEl: { tag: 'div', id: 'additionalLinkDiv', html: (langOfBrowser == 'IT' ? parameters['additionalLabelLinkIT'] : parameters['additionalLabelLinkEN']) } }); if (appVersion!="" && appVersion!="null") { items.push({ xtype: 'component', autoEl: { tag: 'div', id: 'appVersionDiv', className: 'appVersionDiv', html: (appIconVersion!="" && appIconVersion!='null'?(""):"") + appVersion } }); } if(customLoginLabelTranslation) { var footerText = customLoginLabelTranslation(langOfBrowser, "loginFooterText"); if(footerText != null && footerText != '') { items.push({ id: 'footerText', xtype: 'component', autoEl: { tag: 'div', id: 'footerTextDiv', html: footerText } }); } } var subUrl2 = ''; for(var pi in parameters) { if (pi.indexOf("token")!=-1 || pi.indexOf("client")!=-1 || pi.indexOf("login")!=-1) { subUrl2 += "&"+pi.trim()+"="+parameters[pi]; } } var formUrl = '/platform/login?&applicationId=' + applicationId + '&appId=' + applicationId + '&restfulToken='+restfulToken+'&authToken='+authToken + '&ts='+ts + (subUrl2 == '' ? '' : ('&' + subUrl2)); if(parameters['isSsoManagerClass'] == 'y' && parameters['authBoxes']!=null && parameters['authBoxes'].split(",").length>1) formUrl += '&ssoToken=' + 1729236278749; formUrl += "&clientTimeZone="+new Date().getTimezoneOffset()/60; var boxCodes = []; var authBoxes = parameters['authBoxes']; if(authBoxes != null && authBoxes != '') { var tempAuthBoxes = authBoxes.split(","); for(var i=0; i < tempAuthBoxes.length; i++) { boxCodes.push(tempAuthBoxes[i]); } } else { boxCodes.push('AUTH_BOX_DEFAULT'); } var x = 10; var glogin = new Ext.Panel({ x: 10, y: 70, baseCls : 'x-plain', id: 'signinButtonPanel', width: 150, html: '
' }); if (boxCodes.indexOf("AUTH_BOX_GOOGLE")!=-1) x += 150; // Create a variable to hold our EXT Form Panel. // Assign various config options as seen. if(parameters.createToken != null && parameters.createToken == 'Y') { formUrl += '&'; if(parameters.tokenName != null && parameters.tokenName != '') { formUrl += parameters.tokenName + '='; } else { formUrl += 'ssoToken='; } formUrl += 1729236278749; } if(applicationId == 'OFFLINE') { formUrl = '/platform/offlineClientReplication/start?applicationId='+applicationId + '&appId=' + applicationId + '&deviceId=' + parameters['deviceId']; } if(parameters['encriptedCredentials'] == 'true') { formUrl += "&encriptedCredentials=true"; } if(parameters['obfuscatedCredentials'] == 'true') { formUrl += "&obfuscatedCredentials=true"; } // Create a variable to hold our EXT Form Panel. // Assign various config options as seen. var login = new Ext.FormPanel({ x: x, y: 5, //width: 240, labelWidth:80, baseCls : 'x-plain loginPanelItems', ctCls : 'loginPanel', url: formUrl, frame:true, // title: (parameters['appTitle'] == null ? '' : parameters['appTitle']) + ' Login', id: 'loginId', defaultType: 'checkbox', monitorValid:true, items: items //,bbar: buttonsBar }); if(parameters['loginLabelInControls'] != 'Y') login.items.get(0).focus(false,500); if(valHideControls['companyId'] != null) { login.items.get(0).setValue(valHideControls['companyId'] != null ? valHideControls['companyId'] : ''); if(siteIdsDS != null) siteIdsDS.baseParams.companyId = valHideControls['companyId']; } else { if(companyDS != null) companyDS.load(); } login.items.get(1).setValue(valHideControls['siteId'] != null ? valHideControls['siteId'] : null); login.items.get(2).setValue(valHideControls['username'] != null ? valHideControls['username'] : ''); login.items.get(3).setValue(valHideControls['password'] != null ? valHideControls['password'] : null); var otpQrCode = function() { var saved = false; var otpField = new Ext.form.TextField({ x: 85, y: 10, cls: 'field-newotp', width: 200, xtype: 'textfield' }); var w = new Ext.Window({ title: "OTP QRcode", border: true, layout: 'fit', items: [{ xtype: 'panel', layout: 'border', items: [{ region: 'center', xtype: 'panel', height: 300, width: 300, html: "" },{ region: 'south', height: 50, xtype: 'panel', layout: 'absolute', items: [{ xtype: 'label', cls: 'label-newotp', x: 5, y: 10, text: 'OTP' }, otpField ] }] }], width: 300, height: 380, bbar:[{ xtype: 'button', cls: 'otp-button', width: 290, height: 30, text: 'Login', handler: function() { var otp = otpField.getValue(); if (otp==null || otp=="") return; saved = true; login.selectedAuthType = 'mobile'; login.otp = otp; //login.getComponent("otp").setValue(otp); doSubmitForm(); w.close(); } }], listeners: { beforeclose: function(e) { if (!saved) { try { new SyncRequest().send("../googleAuth/deleteQRCode",'GET'); } catch(e) {} } return true; } } }); w.show(); } login.otpQrCode = otpQrCode; var loginFailure = function(action, twoFAWindow) { try { var msg = (action==null?"":(action.response==null?"":(action.response.responseText==null?"":action.response.responseText))); if(action != null && action.failureType == 'server'){ obj = Ext.util.JSON.decode(msg); if (obj.message == "Password expired") { var msgText = obj.message+"
Do you want to change the password?"; if(langOfBrowser == 'IT') { msgText = "Password scaduta.
Vuoi cambiare la tua password?"; } Ext.Msg.confirm('Login failed', msgText, changePassword); return; } else if (obj.message == "OTP not set") { if(twoFAWindow != null) { twoFAWindow.close(); if (mydesktop != null) { if (mydesktop.getManager().getActive() != null) { mydesktop.getManager().getActive().focus(); } } } otpQrCode(); } else if (obj.message == "unset" && login.otp == "unset") { } else { var msgText = obj.message; if(langOfBrowser == 'IT') { if(msgText == 'Invalid credentials') { msgText = "Credenziali non valide."; } } Ext.Msg.alert((langOfBrowser == 'IT' ? 'Login fallita' : 'Login failed'), msgText); login.getForm().reset(); } } else{ try { obj = Ext.util.JSON.decode(msg); if (obj.success!=null && !obj.success && obj.message!=null) Ext.Msg.alert((langOfBrowser == 'IT' ? 'Login fallita' : 'Login failed'), obj.message); else Ext.Msg.alert((langOfBrowser == 'IT' ? 'Login fallita' : 'Login failed'), obj.errormsg); } catch (e) { if (msg == '') { if (e.message!=null && e.message.indexOf("Unexpected token")!=-1) Ext.Msg.alert('Warning', 'Invalid authentication'); else Ext.Msg.alert('Warning', 'Unavailable server: ' + e.message); } else { Ext.Msg.alert('Warning', 'Unavailable server: ' + msg); } } login.getForm().reset(); } } catch(e) { } } var doSubmitForm = function(twoFAWindow) { var companyId = null; if (login.getComponent("companyId")!=null && (hideControls['companyId']==null || hideControls['companyId']!=true)) { if(parameters['encriptedCredentials'] != 'true' && parameters['obfuscatedCredentials'] != 'true') companyId = login.getComponent("companyId").getValue().toUpperCase(); else companyId = login.getComponent("companyId").getValue(); } else if (login.getComponent("companyId")!=null && hideControls['companyId']!=null &&hideControls['companyId']==true && valHideControls['companyId']!=null && valHideControls['companyId']!="") { companyId = login.getComponent("companyId").getValue().toUpperCase(); } if(parameters['isSsoManagerClass'] != 'y') { if (companyId==null) companyId=""; if(companyId.trim().length == 0) return; while(companyId.length<5) { companyId = "0"+companyId; } } if (login.getComponent("companyId")!=null) { login.getComponent("companyId").setValue(companyId); } var username = null; if (login.getComponent("username")!=null && login.getComponent("username").getValue()!=null) { if(parameters['encriptedCredentials'] != 'true' && parameters['obfuscatedCredentials'] != 'true') username = login.getComponent("username").getValue().toUpperCase(); else username = login.getComponent("username").getValue(); } if (login.getComponent("username")!=null) { login.getComponent("username").setValue(username==null?'':username); } if (login.getComponent("password")!=null && (login.getComponent("password").getValue()==null || login.getComponent("password").getValue()=="")) return; var isIE9 = window.navigator.userAgent.indexOf("MSIE 9") != -1; var tempUrl = login.getForm().url; if(login.selectedAuthType != null && login.otp != null) { tempUrl += "&selectedAuthType=" + login.selectedAuthType + "&otp=" + login.otp; } login.getForm().submit({ url: tempUrl, timeout: (isIE9 ? null : 180), method:'POST', waitTitle: (isIE9 ? null : 'Connection'), waitMsg: (isIE9 ? null : 'Sending data...'), success:function(form, action){ var companyId = null; if (login.getComponent("companyId")!=null && (hideControls['companyId']==null || hideControls['companyId']!=true)) { companyId = login.getComponent("companyId").getValue(); } if (companyId!=null) while(companyId.length<5) { companyId = "0"+companyId; } var siteId = null; if (login.getComponent("siteId")!=null && (hideControls['siteId']==null || hideControls['siteId']!=true)) { siteId = login.getComponent("siteId").getValue(); } var username = null; if (login.getComponent("username")!=null) { username = login.getComponent("username").getValue().toUpperCase(); } var password = null; if (login.getComponent("password")!=null) { password = login.getComponent("password").getValue(); } var languageId = null; if (login.getComponent("language")!=null) { languageId = login.getComponent("language").getValue(); } var base = ''; for(var i =Sinesy.util.base64.base64s.length-1;i>=0;i--) { base += Sinesy.util.base64.base64s.substr(i,1); } base=base.replace('S','!').replace('i','S').replace('N','i').replace('e','N').replace('s','e').replace('y','s').replace('!','y'); var hiddenItemIds = parameters['hiddenItemIds'] == null ? '' : parameters['hiddenItemIds']; var defaultValueLoginItems = parameters['defaultValueLoginItems'] == null ? '' : parameters['defaultValueLoginItems']; var redirect = '/platform'; if(applicationId == 'OFFLINE') { redirect += '/4ws/syncinprogress.jsp?'; } else if (parameters['functionId']!=null && parameters['functionId'] != '') { redirect += '/4ws/main_app_function.jsp?functionId=' + parameters['functionId'] + '&'; for(var id in parameters) { if (id!="pwdRegex" && id!="pwdRegexMsg") redirect += id+"="+parameters[id]+"&"; } } else { redirect += '/4ws/main_app.jsp?'; } redirect += 'smartphone='+smartphone+'&'; redirect += 'applicationId='+applicationId; redirect += '&rtk=' +Sinesy.util.base64.encode( 'hiddenItemIds='+(parameters['hiddenItemIds']==null?'':parameters['hiddenItemIds']) +'&defaultValueLoginItems='+(parameters['defaultValueLoginItems']==null?'':parameters['defaultValueLoginItems']) +'&username='+(window.username==null?"":window.username)+ +'&appId='+applicationId +'&applicationId='+applicationId +'&languageId='+languageId +'&appTitle='+title +'&favicon='+parameters.favicon +'&protocol='+window.location.protocol ); redirect += '&isIE=' + (parameters['isIE']==null?'':parameters['isIE']) +'&theme4ws=' + (parameters['theme4ws']==null?'':parameters['theme4ws']) +'¬CalcDeltaMinutesToAdd=' + (parameters['notCalcDeltaMinutesToAdd']==null?'':parameters['notCalcDeltaMinutesToAdd']) +'¬CalcDeltaMinToAddDate=' + (parameters['notCalcDeltaMinToAddDate']==null?'':parameters['notCalcDeltaMinToAddDate']) +'&loginVersion=' + (parameters['loginVersion']==null?'':parameters['loginVersion']) +'&additionalLink=' + (parameters['additionalLink']==null?'':parameters['additionalLink']) +'&additionalLabelLinkIT=' + (parameters['additionalLabelLinkIT']==null?'':parameters['additionalLabelLinkIT']) +'&additionalLabelLinkEN=' + (parameters['additionalLabelLinkEN']==null?'':parameters['additionalLabelLinkEN']) +'&restfulToken='+restfulToken+'&ts='+ts; if (login.items.get('saveAccount').getValue()==true) { if(valHideControls['companyId'] == null || valHideControls['companyId'] == '') cp.set(applicationId + '_c',Sinesy.util.base64.encode(companyId,base)); if(valHideControls['siteId'] == null || valHideControls['siteId'] == '') cp.set(applicationId + '_s',Sinesy.util.base64.encode(siteId,base)); cp.set(applicationId + '_u',Sinesy.util.base64.encode(username,base)); cp.set(applicationId + '_p',Sinesy.util.base64.encode(password,base)); cp.set(applicationId + '_l',Sinesy.util.base64.encode(languageId,base)); } win.close(); if(customLoginCallback) { if(!customLoginCallback(redirect)) { return; } } var mask = new Ext.LoadMask(Ext.getBody()); mask.show(); window.location = redirect; }, failure: function(form, action){ if(customLoginFailure) { customLoginFailure(action, twoFAWindow); } else { loginFailure(action, twoFAWindow); } } }); } login.doSubmitForm = doSubmitForm; var doSubmit = function() { if ((showOtp != null && showOtp == 'Y') || (authToKenMail != null && authToKenMail == 'Y')) { if (login.getComponent("username")!=null && (login.getComponent("username").getValue()==null || login.getComponent("username").getValue()=="")) { return; } if (login.getComponent("password")!=null && (login.getComponent("password").getValue()==null || login.getComponent("password").getValue()=="")) { return; } var obj = { companyId: login.getComponent("companyId").getValue().toUpperCase(), siteId: login.getComponent("siteId").getValue(), username: login.getComponent("username").getValue().toUpperCase(), password: login.getComponent("password").getValue() }; if (login.getComponent("language") != null) { obj.languageId = login.getComponent("language").getValue(); } else { obj.languageId = valHideControls['languageId'] != null ? valHideControls['languageId'] : ''; } var mask = new Ext.LoadMask(Ext.getBody()); mask.show(); var conn = new Ext.data.Connection({timeout: 300000}); conn.request({ url: login.getForm().url + "&onlyCheck=Y", method: 'GET', params: obj, success: function(response, opts) { mask.hide(); var res = Ext.util.JSON.decode(response.responseText); if(res.success) { if(customNextAutentication) { var opts = { contextPath: '/platform' }; customNextAutentication(login, langOfBrowser, showOtp, authToKenMail, res, opts); } else { var paired = res.message == 'paired' ? true : false; nextAutentication(login, langOfBrowser, showOtp, authToKenMail, paired); } } else { if(customLoginFailure) { customLoginFailure({response}); } else { loginFailure({response}); } } }, failure: function(response, opts) { mask.hide(); } }); return; } doSubmitForm(); } if (parameters['autoLogin']!=null && (parameters['autoLogin'] == 'true' || parameters['autoLogin'] == true)) { setTimeout(function(){ doSubmit(); }, 1000); } var cp = new Ext.state.CookieProvider({ path: '/platform/4ws/', secure: false, expires: new Date(new Date().getTime()+(1000*60*60*24*30)) //30 days }); Ext.state.Manager.setProvider(cp); var base = ''; for(var i = Sinesy.util.base64.base64s.length -1; i >=0; i--) { base += Sinesy.util.base64.base64s.substr(i,1); } base=base.replace('S','!').replace('i','S').replace('N','i').replace('e','N').replace('s','e').replace('y','s').replace('!','y'); var companyId = ''; if(valHideControls['companyId'] == null || valHideControls['companyId'] == '') companyId = Sinesy.util.base64.decode(cp.get(applicationId + '_c'),base); var siteId = ''; if(valHideControls['siteId'] == null || valHideControls['siteId'] == '') siteId = Sinesy.util.base64.decode(cp.get(applicationId + '_s'),base); var uname = Sinesy.util.base64.decode(cp.get(applicationId + '_u'),base); var passwd = Sinesy.util.base64.decode(cp.get(applicationId + '_p'),base); var languageId = Sinesy.util.base64.decode(cp.get(applicationId + '_l'),base); if (uname!=null && uname!='' && passwd!=null && passwd!='' && (parameters['autoLogin']!=null && parameters['autoLogin'] != '' ? false: true) ) { if(companyDS != null) companyDS.load(); if(valHideControls['companyId'] == null || valHideControls['companyId'] == '') { if (login.getComponent("companyId")!=null) { login.getComponent("companyId").setValue(companyId); if(siteIdsDS != null) { siteIdsDS.baseParams.companyId = companyId; siteIdsDS.load(); } } } if (valHideControls['siteId'] == null || valHideControls['siteId'] == '') { if (login.getComponent("siteId")!=null) { login.getComponent("siteId").setValue(siteId); } } if (login.getComponent("username")!=null) { login.getComponent("username").setValue(uname.toUpperCase()); } if (login.getComponent("password")!=null) { login.getComponent("password").setValue(passwd); } if (login.getComponent("saveAccount")!=null) { login.getComponent("saveAccount").setValue(true); } if (login.getComponent("language")!=null) { login.getComponent("language").setValue(languageId); } if (login.getComponent("languageId")!=null) { login.getComponent("languageId").setValue(languageId); } } var h = 170; if(hideControls['companyId'] == null || !hideControls['companyId']) { h += 30; } if(hideControls['siteId'] == null || !hideControls['siteId']) { h += 30; } if(hideControls['language'] == null || !hideControls['language']) { h += 30; } if(hideControls['forgotpwd'] == null || !hideControls['forgotpwd']) { h += 30; } if(hideControls['additionalLink'] == null || !hideControls['additionalLink']) { h += 30; } var w = 0; var boxes = []; if (boxCodes.indexOf("AUTH_BOX_GOOGLE")!=-1) { boxes.push(glogin); w += 150; } if (boxCodes.indexOf("AUTH_BOX_DEFAULT")!=-1) { boxes.push(login); w += 300; } var win = new Ext.Window({ ctCls : 'loginWindow', layout: 'absolute', width: w+20, height: h, id : 'loginWindow', title: (parameters['appTitle'] == null ? '' : parameters['appTitle']) + ' Login', closable: false, resizable: false, plain: true, border: false, modal: true, items: boxes, listeners: { show: function(o) { if (loadGoogleLibs) { checkGButton(); } } } }); function checkGButton() { document.getElementById("forgotpwdDiv").parentNode.append(document.getElementById("signinButton")); if (parameters['loginLabelInControls'] == 'N') document.getElementById("signinButton").style["margin-left"] = "60px"; } win.width = w+20; win.height = h; if (login!=null && parameters!=null && "true"==parameters["autoLogin"] ) { login.addListener("afterrender",function() { login.hide(); }); } win.show(); win.center(); if (hideControls['forgotpwd']== null || hideControls['forgotpwd']==false) { var forgotpwdDiv = document.getElementById("forgotpwdDiv"); if (forgotpwdDiv!=null) { forgotpwdDiv.setAttribute("className","forgotpwd"); forgotpwdDiv.setAttribute("class","forgotpwd"); forgotpwdDiv.onclick = function() { if(login.getComponent("companyId") != null) { parameters['companyId'] = login.getComponent("companyId").getValue(); } if(login.getComponent("siteId") != null) { parameters['siteId'] = login.getComponent("siteId").getValue(); } forgotPassword(parameters); }; win.setHeight(win.getHeight()+30); } } if (parameters['forgotpwd'] != null && parameters['forgotpwd'] == 'Y') { var plainText = 'username='; if (window.username!=null && window.username.getValue!=null) plainText += window.username.getValue(); else plainText += parameters['username']; plainText += '&appId='+parameters['applicationId'] +'&companyId=' + parameters['companyId'] +'&siteId=' + parameters['siteId'] +'&oldpwd='+ parameters['password']; var url = '/platform/login/checkOldPwd?applicationId=' + parameters['applicationId'] + '&rtk='+ Sinesy.util.base64.encode(plainText) + '&ts='+1729236278758; var conn = new Ext.data.Connection({timeout: 300000}); conn.request({ url: url, method: 'GET', success: function(resp,opt) { var risp = Ext.util.JSON.decode(resp.responseText); if(!risp.success) { login.getComponent("companyId").setValue(''); login.getComponent("siteId").setValue(''); login.getComponent("username").setValue(''); login.getComponent("password").setValue(''); } else { changePassword('yes', null); } }, failure: function(resp,opt) { login.getComponent("companyId").setValue(''); login.getComponent("siteId").setValue(''); login.getComponent("username").setValue(''); login.getComponent("password").setValue(''); } }); } if (hideControls['additionalLink']== null || hideControls['additionalLink']==false) { var additionalLinkDiv = document.getElementById("additionalLinkDiv"); if (additionalLinkDiv!=null) { additionalLinkDiv.setAttribute("className","additionalLink"); additionalLinkDiv.setAttribute("class","additionalLink"); additionalLinkDiv.onclick = function() { window.open(parameters['additionalLink']); }; win.setHeight(win.getHeight()+30); } } // AB - WAG-97 - 12/12/2012 // change password if it is expired function changePassword(btn, tmp1){ if (btn=='yes') { var ts = '1729236278733'; var applicationId = parameters['applicationId'] == null ? '' : parameters['applicationId']; var title = parameters['appTitle'] == null ? '' : parameters['appTitle']; var companyId = Ext.getCmp('companyId') != null ? Ext.getCmp('companyId').getValue() : null; var siteId = Ext.getCmp('siteId') != null ? Ext.getCmp('siteId').getValue() : null; var username = Ext.getCmp('username') != null ? Ext.getCmp('username').getValue().toUpperCase() : null; var forgotpwd = parameters['forgotpwd'] == null ? '' : parameters['forgotpwd']; if(forgotpwd == 'Y') { companyId = parameters['companyId']; siteId = parameters['siteId']; username = parameters['username']; } var buttonBarChangePwd = new Ext.Panel({ baseCls: 'x-plain', layout: 'absolute', height: 30, width: '100%', items: [ ] }); if (parameters['loginVersion'] == null || parameters['loginVersion'] == '' || parameters['loginVersion'] == '1') { buttonBarChangePwd.add(new Ext.Button({ x: 1, y:1, text: (langOfBrowser == 'IT' ? 'Cambia password' : 'Change password'), width: 130, handler: function() { doChangePassword(); } }) ); } else if (parameters['loginVersion'] == '2') { buttonBarChangePwd.add(new Ext.Button({ x: 140, y:1, text: (langOfBrowser == 'IT' ? 'Cambia password' : 'Change password'), width: 130, handler: function() { doChangePassword(); } }) ); } var url = '/platform/login/changepassword?applicationId=' + parameters['applicationId'] // + '&companyId='+companyId+ // '&siteId='+siteId //+'&username='+username +'&ts='+ts; /* if(parameters['isSsoManagerClass'] == 'y') url += '&ssoToken=' + 1729236278758; if(parameters['pwdGgExpired'] != null && parameters['pwdGgExpired'] != '') { url += '&addDays=' + parameters['pwdGgExpired']; } if(parameters['pwdMemorizedNum'] != null && parameters['pwdMemorizedNum'] != '') { url += '&pwdMemorizedNum=' + parameters['pwdMemorizedNum']; } if(forgotpwd == 'Y') { url += '&forgotpwd=' + forgotpwd; } */ var changePwd = new Ext.FormPanel({ ctCls : 'loginPanel', //'resetPasswordLoginPanel', cls : 'changePwd', //'resetPasswordLoginPanel', labelWidth:120, url: url, frame:true, title: title + ' Change password', defaultType: 'checkbox', monitorValid:true, items:[ { xtype: 'textfield', fieldLabel: (langOfBrowser == 'IT' ? 'Vecchia password' : 'Old password'), name:'oldPassword', itemId:'oldPassword', inputType:'password', allowBlank:false, width: 150, enableKeyEvents: true, listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doChangePassword(); } }, hidden: forgotpwd != '' ? true : false, value: forgotpwd != '' ? parameters['password'] : '' },{ xtype: 'textfield', fieldLabel:(langOfBrowser == 'IT' ? 'Nuova password' : 'New password'), name:'newPassword', itemId:'newPassword', inputType:'password', width: 150, allowBlank:false, enableKeyEvents: true, listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doChangePassword(); }, "blur": function(field) { if(parameters.pwdRegex != null && parameters.pwdRegex != '') { var exp = new RegExp(parameters.pwdRegex); if(!exp.test(field.getValue())) { var msg = 'Password not valid.'; if(customLoginLabelTranslation) { msg = customLoginLabelTranslation(langOfBrowser, "pwdRegexMsg"); } else if(parameters.pwdRegexMsg != null && parameters.pwdRegexMsg != '') { msg = parameters.pwdRegexMsg; if(msg.indexOf("=") > -1) { var msgs = msg.split(","); msg = msgs[0].substring(msg.indexOf("=")+1); if(msgs.length > 1) { for(var i=0; i < msgs.length; i++) { var lang = msgs[i].substring(0, msgs[i].indexOf("=")); if(lang == langOfBrowser) { msg = msgs[i].substring(msgs[i].indexOf("=")+1); break; } } } } } Ext.Msg.alert('Error', msg); field.setValue(null); return; } } } } },{ xtype: 'textfield', fieldLabel:(langOfBrowser == 'IT' ? 'Conferma password' : 'Confirm password'), name:'confirmPassword', itemId:'confirmPassword', inputType:'password', width: 150, allowBlank:false, enableKeyEvents: true, listeners: { "keydown": function(comp,event){ if (event.getKey()==13) doChangePassword(); } } }], bbar: buttonBarChangePwd }); changePwd.items.get(0).focus(false,500); } var doChangePassword = function() { var oldPasswordTmp = changePwd.items.get(0).getValue(); var newPasswordTmp = changePwd.items.get(1).getValue(); var confirmPasswordTmp = changePwd.items.get(2).getValue(); if (oldPasswordTmp == null || oldPasswordTmp == '' || newPasswordTmp == null || newPasswordTmp == '' || confirmPasswordTmp == null || confirmPasswordTmp == '' ) { return; } if (newPasswordTmp != confirmPasswordTmp) { Ext.Msg.alert('Change password', 'New password and confirm password must be the same'); } else if (newPasswordTmp == oldPasswordTmp) { Ext.Msg.alert('Change password', 'New password must be different from old passowrd'); } else { while(companyId.length<5) companyId = "0"+companyId; /* login.items.get(0).setValue(companyId); var username = login.items.get(2).getValue().toUpperCase(); login.items.get(2).setValue(username); */ var paramsObj = new Object(); paramsObj['username'] = username; paramsObj['companyId'] = companyId; paramsObj['siteId'] = siteId; if(parameters['isSsoManagerClass'] == 'y') // url += '&ssoToken=' + 1729236278758; paramsObj['ssoToken'] = '1729236278758'; if(parameters['pwdGgExpired'] != null && parameters['pwdGgExpired'] != '') { // url += '&addDays=' + parameters['pwdGgExpired']; paramsObj['addDays'] = parameters['pwdGgExpired']; } if(parameters['pwdMemorizedNum'] != null && parameters['pwdMemorizedNum'] != '') { // url += '&pwdMemorizedNum=' + parameters['pwdMemorizedNum']; paramsObj['pwdMemorizedNum'] = parameters['pwdMemorizedNum']; } if(forgotpwd == 'Y') { // url += '&forgotpwd=' + forgotpwd; paramsObj['forgotpwd'] = forgotpwd; } changePwd.getForm().submit({ timeout: 60, method:'POST', params: paramsObj, waitTitle:'Connection', waitMsg:'Sending data...', success:function(form, action){ // +AB - WAG-470 - 23/10/2014 // redirect to login form...and call doSubmit method //var redirect = '/platform/4ws/main_app.jsp?username='+username+'&applicationId='+applicationId+'&appTitle='+title+'&ts='+ts; var login = Ext.getCmp('loginId'); var password = null; if (changePwd.getComponent("newPassword")!=null) { /* if(parameters['companyId']) login.getComponent("companyId").setValue(parameters['companyId']); if(parameters['siteId']) login.getComponent("siteId").setValue(parameters['siteId']); if(parameters['username']) login.getComponent("username").setValue(parameters['username']); */ password = changePwd.getComponent("newPassword").getValue(); login.getComponent("password").setValue(password); } win.close(); // +MC 2016/12/23 var res = eval("("+action.response.responseText+")"); var isMobile = res.isMobile; if (isMobile==null || !isMobile) doSubmit(); else { Ext.Msg.alert("Operation completed","Password has been successfully changed.",function() { window.location="emptyPage.jsp" }); } // AB /* var mask = new Ext.LoadMask(Ext.getBody()); mask.show(); window.location = redirect;*/ }, failure:function(form, action){ if(action.failureType == 'server'){ obj = Ext.util.JSON.decode(action.response.responseText); if (obj.message == "Password expired") { Ext.Msg.confirm('Login failed', obj.message+"
Do you want to change the password?", changePassword); } else { Ext.Msg.alert('Login failed', obj.message); } } else{ try { obj = Ext.util.JSON.decode(action.response.responseText); if (obj.success!=null && !obj.success && obj.message!=null) Ext.Msg.alert('Login failed', obj.message); else Ext.Msg.alert('Login failed', obj.errormsg); } catch (e) { Ext.Msg.alert('Warning', 'Unavailable server: ' + action.response.responseText); } } changePwd.getForm().reset(); } }); } }; var cp = new Ext.state.CookieProvider({ path: '/platform/4ws/', secure: false, expires: new Date(new Date().getTime()+(1000*60*60*24*30)) //30 days }); var win = new Ext.Window({ ctCls : 'resetPasswordLoginWindow', layout:'fit', width:320, height: forgotpwd != '' ? 170 : 200, closable: false, resizable: false, plain: true, border: false, modal: true, items: [changePwd] }); win.show(); }; }); function forgotPassword(parameters) { var title = 'Forgot Password'; var message = 'E-mail'; var modal = true; /* if (Ext.isIE) { Ext.Msg.show({ title: title, msg: message, buttons: Ext.Msg.OK, fn: okFun, animEl: 'elId', icon: Ext.MessageBox.INFO }); return; } */ var controlsWidth = parameters['loginLabelInControls'] == 'Y' ? 300 : 250; var items = []; if(parameters['comboOfCompanySite'] == 'Y') { var companyDS = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/platform/getApplications/getCompanies', method: 'GET' }), reader: new Ext.data.JsonReader({ root: 'valueObjectList', totalProperty: 'resultSetLength' }, [ {name: 'pk_companyId', mapping: 'pk.companyId'}, , {name: 'pk.siteId', type: 'int'} , {name: 'pk.subjectId'} , {name: 'siteIdLku08', type: 'float'} , {name: 'lawNatureIdLku08'} , {name: 'siteIdLku05', type: 'float'} , {name: 'typeCompanyActivityIdLku05'} , {name: 'corporateName1', mapping: 'corporateName1'} , {name: 'corporateName2'} , {name: 'shortDescription'} , {name: 'address'} , {name: 'zipCode'} , {name: 'city'} , {name: 'country'} , {name: 'countryIdLku07'} , {name: 'lawfulSite'} , {name: 'companySecurityCode'} , {name: 'siteIdSub01', type: 'float'} , {name: 'subjectIdSub01'} , {name: 'createDate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'} , {name: 'userIdCreate'} , {name: 'lastUpdate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'} , {name: 'userIdUpdate'} , {name: 'rowVersion', type: 'int'} , {name: 'status'} , {name: 'siteIdLku29', type: 'float'} , {name: 'placeIdLku29'} , {name: 'note'} , {name: 'companyCf'} , {name: 'eMail'} , {name: 'siteIdCustSub35', type: 'float'} , {name: 'interestLevelCustIdSub35'} , {name: 'siteIdSub35', type: 'float'} , {name: 'interestLevelIdSub35'} , {name: 'siteIdSub40', type: 'float'} , {name: 'typeOrganizationIdSub40'} , {name: 'siteIdSub42', type: 'float'} , {name: 'rangeIdSub42'} , {name: 'totalInvoice', type: 'float'} , {name: 'yearTotalInvoice', type: 'float'} , {name: 'totalEmployee', type: 'float'} , {name: 'siteIdRefSub01', type: 'float'} , {name: 'subjectIdRefSub01'} , {name: 'siteIdLku59', type: 'float'} , {name: 'typePurchaseIdLku59'} , {name: 'province'} , {name: 'region'} , {name: 'telephone'} , {name: 'fax'} , {name: 'deliveryNote'} , {name: 'mobile'} , {name: 'siteIdSub50', type: 'float'} , {name: 'featureIdSub50'} , {name: 'siteIdSub52', type: 'float'} , {name: 'saleTypeIdSub52'} , {name: 'budgetTotalInvoice', type: 'float'} , {name: 'yearBudgetTotalInvoice', type: 'float'} , {name: 'yearOurTotalInvoice', type: 'float'} , {name: 'ourTotalInvoice', type: 'float'} , {name: 'priceListTypeId'} , {name: 'numberCopies', type: 'float'} , {name: 'siteIdSub56', type: 'float'} , {name: 'targetIdSub56'} ]), remoteSort:true, batch: true, autoSave: false }); items.push( { xtype: 'combo', typeAhead: true, fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (parameters['langOfBrowser'] == 'IT' ? "Societ\u00E0" : 'Company Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'companyId', itemId:'companyId', //id:'companyId', triggerAction: 'all', lazyRender: false, width: controlsWidth, mode: 'remote', store: companyDS, valueField: 'pk_companyId', hiddenName:'companyId', displayField: 'corporateName1', //autoSelect: true, forceSelection: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (parameters['langOfBrowser'] == 'IT' ? "Societ\u00E0" : 'Company Id') : '', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '', hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false, listeners: { /* 'change': function(combo, newValue, oldValue) { if(newValue != null && newValue != '') { } } */ } } ); } else { items.push( { xtype: 'textfield', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (parameters['langOfBrowser'] == 'IT' ? 'Società' : 'Company Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'companyId', itemId:'companyId', // id:'companyId', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, width: controlsWidth, enableKeyEvents: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (parameters['langOfBrowser'] == 'IT' ? 'Società' : 'Company Id') : '', value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '', hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false } ); } if(parameters['comboOfCompanySite'] == 'Y') { var siteIdsDS = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/platform/getApplications/getSiteIdsList', method: 'GET' }), reader: new Ext.data.JsonReader({ root: 'valueObjectList', totalProperty: 'resultSetLength' }, [ {name: 'pk_siteId',type: 'int'}, {name: 'description'} ]), sortInfo: {field: 'pk.siteId', direction: 'ASC'}, remoteSort:true, batch: true, autoSave: false }); items.push( { xtype: 'combo', typeAhead: true, fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (parameters['langOfBrowser'] == 'IT' ? 'Sito' : 'Site Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'siteId', itemId:'siteId', triggerAction: 'all', lazyRender: false, width: controlsWidth, mode: 'remote', store: siteIdsDS, valueField: 'pk_siteId', hiddenName:'siteId', displayField: 'description', autoSelect: true, forceSelection: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (parameters['langOfBrowser'] == 'IT' ? 'Sito' : 'Site Id') : '', allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '', hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false, listeners: { beforequery : function(qe) { var combo = qe.combo; if(form.getComponent("companyId") != null) { combo.store.baseParams.companyId = form.getComponent("companyId").getValue(); } delete combo.lastQuery; } } }); } else { items.push({ xtype: 'textfield', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id'), hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, name:'siteId', itemId:'siteId', width: controlsWidth, allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true, enableKeyEvents: true, emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id') : '', value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '', hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false }); } items.push( { xtype: 'textfield', width: controlsWidth, itemId: 'field', fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : message, hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false, emptyText : parameters['loginLabelInControls'] == 'Y' ? message : '' } ); var form = new Ext.FormPanel({ baseCls : 'x-plain loginPanelItems forgotPanelItems', ctCls : 'forgotPanel', // layout: 'absolute', defaultType: 'textfield', labelWidth:80, frame:true, monitorValid:true, items: items }); if(parameters['comboOfCompanySite'] == 'Y') { if(parameters["companyId"] != null && parameters["companyId"] != '') { form.getComponent('companyId').setValue(parameters["companyId"]); form.getComponent('companyId').disable(); } else { companyDS.addListener("load",function(store, records, options) { var combo = form.getComponent('companyId'); if (combo != null && combo.getValue() != null && combo.getValue() != '') { siteIdsDS.load(); } if(companyDS.getCount() == 1) { var record = companyDS.getAt(0); combo.setValue(records[0].data.pk_companyId); siteIdsDS.load(); } }); } if(parameters["siteId"] != null && parameters["siteId"] != '') { form.getComponent('siteId').store.baseParams.companyId = parameters["companyId"]; form.getComponent('siteId').setValue(parameters["siteId"]); form.getComponent('siteId').disable(); } else { siteIdsDS.addListener("load",function(store, records, options) { var combo = form.getComponent('siteId'); if (combo != null && combo.getValue() != null && combo.getValue() != '') { combo.validate(); return; } if (siteIdsDS.getCount() < 1) { combo.setValue(null); } else if (siteIdsDS.getCount() == 1) { var record = siteIdsDS.getAt(0); combo.setValue(records[0].data.pk_siteId); } }); } } var okButton = new Ext.Button({ text: (parameters['langOfBrowser'] == 'IT' ? 'Invia' : 'Send'), itemId: 'ok', handler: function() { if (form.getComponent("companyId") == null || form.getComponent("companyId").getValue()==null || form.getComponent("companyId").getValue()=='') return; if (form.getComponent("siteId") == null || form.getComponent("siteId").getValue()==null || form.getComponent("siteId").getValue()=='') return; if (form.getComponent("field") == null || form.getComponent("field").getValue()==null || form.getComponent("field").getValue()=='') return; var mask = new Ext.LoadMask(Ext.getBody(), {msg:"Sending mail..."}); mask.show(); var url = '/platform/login/resetpassword?applicationId=' + parameters['applicationId'] + '&ts='+1729236278758 + '&isIE=' + Ext.isIE; var conn = new Ext.data.Connection({timeout: 300000}); conn.request({ url: url, method: 'GET', params: { companyId: form.getComponent("companyId") != null ? form.getComponent("companyId").getValue() : null, siteId: form.getComponent("siteId") != null ? form.getComponent("siteId").getValue() : null, email: form.getComponent("field") != null ? form.getComponent("field").getValue() : null, baseUrl: document.referrer, appTitle: parameters['appTitle'] }, success: function(resp,opt) { mask.hide(); var risp = Ext.util.JSON.decode(resp.responseText); if(!risp.success) { Ext.Msg.show({ title:'Error', msg: risp.message, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR, defaultTextHeight : 150, fn: function(){} }); } else { Ext.Msg.show({ title:'Info', msg: 'Password reset email sent.\nCheck your inbox.', buttons: Ext.Msg.OK, icon: Ext.MessageBox.INFO, defaultTextHeight : 150, fn: function(){} }); window.close(); if (mydesktop!=null) { if (mydesktop.getManager().getActive()!=null) { mydesktop.getManager().getActive().focus(); } } } }, failure: function(resp,opt) { mask.hide(); Ext.Msg.show({ title:'Error', msg: resp.statusText, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR, defaultTextHeight : 150, fn: function(){} }); } }); } }); var cancelButton = new Ext.Button({ text: (parameters['langOfBrowser'] == 'IT' ? 'Annulla' : 'Cancel'), handler: function() { window.close(); if (mydesktop!=null) if (mydesktop.getManager().getActive()!=null) mydesktop.getManager().getActive().focus(); } }); var buttons = []; buttons.push(okButton); buttons.push(cancelButton); var window = null; if (mydesktop!=null) { window = mydesktop.createWindow({ ctCls : 'loginWindow', title: title, width: 450, height: 130 + (hideControls['companyId'] != null ? (hideControls['companyId'] == true ? 0 : 50) : 50) + (hideControls['siteId'] != null ? (hideControls['siteId'] == true ? 0 : 50) : 50) , minWidth: 450, minHeight: 160 + (hideControls['companyId'] != null ? (hideControls['companyId'] == true ? 0 : 50) : 50) + (hideControls['siteId'] != null ? (hideControls['siteId'] == true ? 0 : 50) : 50) , maximizable: false, minimizable: false, closable: false, layout: 'fit', plain:true, manager: mydesktop.getManager(), bodyStyle:'padding:5px;', buttonAlign:'center', modal: modal==null?false:modal, items: [form], focus: function(){ okButton.focus(); }, buttons: buttons }); } else { window = new Ext.Window({ ctCls : 'loginWindow', title: title, width: 450, height: 130 + (hideControls['companyId'] != null ? (hideControls['companyId'] == true ? 0 : 50) : 50) + (hideControls['siteId'] != null ? (hideControls['siteId'] == true ? 0 : 50) : 50) , minWidth: 450, minHeight: 160 + (hideControls['companyId'] != null ? (hideControls['companyId'] == true ? 0 : 50) : 50) + (hideControls['siteId'] != null ? (hideControls['siteId'] == true ? 0 : 50) : 50) , maximizable: false, minimizable: false, closable: false, layout: 'fit', plain:true, bodyStyle:'padding:5px;', buttonAlign:'center', modal: modal==null?false:modal, items: [form], focus: function(){ okButton.focus(); }, buttons: buttons }); } if (parameters!=null && "true"==parameters["autoLogin"] ) { } else { window.show(); if(parameters["companyId"] != null && parameters["companyId"] != '') { form.getComponent('companyId').setValue(parameters["companyId"]); } if(parameters["siteId"] != null && parameters["siteId"] != '') { form.getComponent('siteId').setValue(parameters["siteId"]); } } } function nextAutentication(loginForm, langOfBrowser, showOtp, authToKenMail, paired) { var items = []; var selectedAuthType = ''; var radioItems = []; if (showOtp != null && showOtp == 'Y') { radioItems.push({ boxLabel: 'OTP Mobile', name: 'rb-auto', inputValue: 1, authType: 'mobile' }); } if (authToKenMail != null && authToKenMail == 'Y') { radioItems.push({ boxLabel: 'Email', name: 'rb-auto', inputValue: 2, authType: 'mail' }); } var validate = function() { if (selectedAuthType == '') { return; } var code = login.getComponent('code'); var otp = 'unset'; if (code != null && code.getValue() != null && code.getValue() != '') { otp = code.getValue(); } loginForm.selectedAuthType = selectedAuthType; loginForm.otp = otp; win.close(); if (mydesktop != null) if (mydesktop.getManager().getActive() != null) mydesktop.getManager().getActive().focus(); loginForm.doSubmitForm(); } items.push({ xtype: 'radiogroup', //fieldLabel: 'Auto Layout', cls: 'x-check-group-alt', name: 'type', itemId: 'type', items: radioItems, listeners: { "change": function(group, checked) { selectedAuthType = checked.authType; if (checked.inputValue == 1) { loginForm.selectedAuthType = selectedAuthType; loginForm.otp = 'unset'; loginForm.doSubmitForm(win); } else if (checked.inputValue == 2) { var mask = new Ext.LoadMask(Ext.getBody(), {msg:"Sending mail..."}); mask.show(); var url = '/platform/login/sendOtpForLogin?applicationId=' + parameters['applicationId'] + '&selectedAuthType=' + selectedAuthType + '&ts='+1729236278758; var conn = new Ext.data.Connection({timeout: 300000}); conn.request({ url: url, method: 'POST', params: { companyId: loginForm.getComponent("companyId") != null ? loginForm.getComponent("companyId").getValue() : null, siteId: loginForm.getComponent("siteId") != null ? loginForm.getComponent("siteId").getValue() : null, uname: loginForm.getComponent("username") != null ? loginForm.getComponent("username").getValue() : null, passwd: loginForm.getComponent("password") != null ? loginForm.getComponent("password").getValue() : null, appTitle: parameters['appTitle'] }, success: function(resp,opt) { mask.hide(); }, failure: function(resp,opt) { mask.hide(); } }); } } } }); items.push({ xtype: 'textfield', fieldLabel: (langOfBrowser == 'IT' ? 'Codice' : 'Code'), name: 'code', itemId: 'code', width: 240, allowBlank: false, //value: 'unset', listeners: { "keydown": function(comp, event) { if (event.getKey() == 13) validate(); } } }); var buttonsBar = []; buttonsBar.push(new Ext.Button({ x: 1, y: 10, text: (langOfBrowser == 'IT' ? 'Accedi' : 'Login'), width: 75, handler: function() { validate(); } })); buttonsBar.push( new Ext.Button({ x: 200, y: 10, text: (langOfBrowser == 'IT' ? 'Cancella' : 'Cancel'), width: 75, handler: function() { win.close(); if (mydesktop != null) if (mydesktop.getManager().getActive() != null) mydesktop.getManager().getActive().focus(); } }) ); // Create a variable to hold our EXT Form Panel. // Assign various config options as seen. var login = new Ext.FormPanel({ labelWidth: 50, baseCls : 'x-plain loginPanelItems twofaPanelItems', ctCls : 'twofaPanel', frame: true, defaultType: 'checkbox', monitorValid: true, id: '2fapanel', items: items }); var win = null; if (mydesktop!=null) { win = mydesktop.createWindow({ ctCls : 'loginWindow', title: 'Login 2FA', width: 350, height: 170, minWidth: 350, minHeight: 170, maximizable: false, minimizable: false, closable: true, layout: 'fit', plain:true, manager: mydesktop.getManager(), bodyStyle:'padding:5px;', buttonAlign:'center', modal: true, items: [login], buttons: buttonsBar }); } else { win = new Ext.Window({ ctCls : 'loginWindow', title: 'Login 2FA', width: 350, height: 170, minWidth: 350, minHeight: 170, maximizable: false, minimizable: false, closable: false, layout: 'fit', plain:true, bodyStyle:'padding:5px;', buttonAlign:'center', modal: true, items: [login], buttons: buttonsBar }); } win.show(); }