CallBackery
view release on metacpan or search on metacpan
lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/Login.js view on Meta::CPAN
alignX: 'right'
})
).set({
paddingTop: 10
});
this.add(extraActions, {
row: 5,
column: 0,
colSpan: 3
});
if (cfg.passwordreset_popup) {
let btn = this.__passwordresetBtn = this.__makeExtraButton(
cfg.passwordreset_popup,this.tr("Reset Password")
);
extraActions.add(btn);
}
if (cfg.registration_popup) {
let btn = this.__registrationBtn = this.__makeExtraButton(
cfg.registration_popup,this.tr("Register New Account")
);
extraActions.add(btn);
}
if ( cfg.company_name && !cfg.hide_company){
var who = '';
if (cfg.company_url){
who += '<a href="' + cfg.company_url + '" style="color: #444;" target="_blank">' + cfg.company_name + '</a>';
}
else {
who += cfg.company_name;
}
}
if (! cfg.hide_release) {
this.add(new qx.ui.basic.Label(this.tr('release %1, %2 by %3','#VERSION#','#DATE#',who)).set({
textColor : '#444',
rich : true
}), {
row : 6,
column : 0,
colSpan: 3
});
}
this.addListener('keyup', function(e) {
if (e.getKeyIdentifier() == 'Enter') {
login.press();
login.execute();
login.release();
}
});
var rpc = callbackery.data.Server.getInstance();
login.addListener("execute", function(e) {
this.setEnabled(false);
var passwordValue;
if (! cfg.hide_password) {
passwordValue = password.getValue();
}
// The credentials are handed to the hidden iframe form in the
// handler, once the login actually succeeded. Nothing about the
// iframe happens before this call: it is a convenience for the
// browser's password manager and must never be able to stop a
// login. It used to run here, and whenever the iframe had not
// finished loading /login the null it returned threw before this
// line ever ran -- leaving the form disabled forever with no
// request sent and nothing on screen to say why.
rpc.callAsync(qx.lang.Function.bind(
this.__loginHandler, this, username.getValue(), passwordValue),
'login',
username.getValue(),
passwordValue
);
},
this);
let urlCfg = callbackery.data.Config.getInstance().getUrlConfig();
this.addListener('appear', function() {
if (! cfg.hide_password) {
password.setValue('');
}
this.setEnabled(true);
if (username.getValue()){
username.set({
enabled: false,
readOnly: true,
focusable: false
});
if (! cfg.hide_password) {
password.focus();
password.activate();
}
}
else {
username.focus();
username.activate();
}
this.__ensureIframe();
if (urlCfg.app === 'registration' && this.__registrationBtn){
this.__registrationBtn.fireEvent('tap');
}
else if (urlCfg.app === 'passwordreset' && this.__passwordresetBtn){
this.__passwordresetBtn.fireEvent('tap');
}
},this);
},
events : { 'login' : 'qx.event.type.Event' },
members : {
/**
* Hand the credentials to the browser's password manager by filling
* the hidden iframe form and submitting it.
*
* Best effort by design. The iframe reloads /login on every appear,
* so its document can still be blank when this runs and
* getElementById then returns null. That is a missed save prompt and
* nothing more, so every step is guarded and the caller ignores the
* outcome -- this must never come between the user and their session.
*
* @param username {String} the user name to offer for saving
* @param password {String} the password to offer, may be undefined
* @return {void}
*/
__rememberCredentials: function(username, password) {
try {
var doc = this.__getIframeDocument();
var form = doc && doc.getElementById('cbLoginForm');
var userField = doc && doc.getElementById('cbUsername');
var passField = doc && doc.getElementById('cbPassword');
if (!form || !userField) {
this.debug('login iframe not ready, skipping the password save prompt');
return;
}
userField.value = username;
if (password !== undefined && passField) {
passField.value = password;
}
form.submit();
}
catch (e) {
this.debug('could not offer the credentials for saving: ' + e);
}
},
/**
* Handler for the login events
*
* @param username {String} the user name that was submitted.
* @param password {String} the password that was submitted, may be undefined.
* @param ret {Boolean} true if the login is ok and false if it is not ok.
* @param exc {Exception} any error found during the login process.
* @return {void}
*/
__iframe: null,
__passwdBtn: null,
__registrationBtn: null,
__ensureIframe: function(){
var iframe = document.getElementById("cbLoginIframe");
if (!iframe) {
iframe = qx.dom.Element.create('iframe',{
id: "cbLoginIframe",
style: "width:0px;height:0px;border:0px;"
});
document.body.appendChild(iframe);
}
iframe.setAttribute('src',
'login?nocache='+Math.round(1000000*Math.random()).toString(16));
return iframe;
},
__getIframeDocument: function(){
var iframe = this.__iframe;
return iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
},
__loginHandler : function(username, password, ret, exc) {
if (exc == null) {
if (qx.lang.Type.isObject(ret) && ret.sessionCookie) {
this.__rememberCredentials(username, password);
this.fireDataEvent('login', ret);
this.close();
}
else {
var element = this.getContentElement().getDomElement();
var tada = {duration: 1000, keyFrames : {
0 : {scale: 1, rotate: "0deg"},
10 : {scale: 0.9, rotate: "-3deg"},
20 : {scale: 0.9, rotate: "-3deg"},
30 : {scale: 1.1, rotate: "3deg"},
40 : {scale: 1.1, rotate: "-3deg"},
50 : {scale: 1.1, rotate: "3deg"},
60 : {scale: 1.1, rotate: "-3deg"},
70 : {scale: 1.1, rotate: "3deg"},
80 : {scale: 1.1, rotate: "-3deg"},
90 : {scale: 1.1, rotate: "3deg"},
100 : {scale: 1, rotate: "0deg"}
}};
qx.bom.element.Animation.animate(element,tada);
this.setEnabled(true);
}
}
else {
callbackery.ui.MsgBox.getInstance().exc(exc);
( run in 1.595 second using v1.01-cache-2.11-cpan-007c89162af )