Commit cf75946e authored by JC Brand's avatar JC Brand

Make fetchLoginCredentials a function

parent e9e17cb2
......@@ -63750,6 +63750,36 @@ async function finishInitialization() {
}
}
function fetchLoginCredentials() {
new es6_promise_dist_es6_promise_auto__WEBPACK_IMPORTED_MODULE_3___default.a((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
}
function unregisterGlobalEventHandlers() {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
......@@ -64479,34 +64509,6 @@ _converse.initialize = async function (settings, callback) {
});
this.fetchLoginCredentials = () => new es6_promise_dist_es6_promise_auto__WEBPACK_IMPORTED_MODULE_3___default.a((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
this.startNewBOSHSession = function () {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.prebind_url, true);
......@@ -64604,7 +64606,7 @@ _converse.initialize = async function (settings, callback) {
this.autoLogin(credentials);
} else if (this.auto_login) {
if (this.credentials_url) {
this.fetchLoginCredentials().then(this.autoLogin.bind(this), this.autoLogin.bind(this));
fetchLoginCredentials().then(this.autoLogin.bind(this), this.autoLogin.bind(this));
} else if (!this.jid) {
throw new Error("attemptNonPreboundSession: If you use auto_login, " + "you also need to give either a jid value (and if " + "applicable a password) or you need to pass in a URL " + "from where the username and password can be fetched " + "(via credentials_url).");
} else {
......@@ -483,6 +483,31 @@ async function finishInitialization () {
}
}
function fetchLoginCredentials () {
new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
}
function unregisterGlobalEventHandlers () {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
......@@ -1123,30 +1148,6 @@ _converse.initialize = async function (settings, callback) {
});
this.fetchLoginCredentials = () =>
new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
this.startNewBOSHSession = function () {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.prebind_url, true);
......@@ -1243,7 +1244,7 @@ _converse.initialize = async function (settings, callback) {
this.autoLogin(credentials);
} else if (this.auto_login) {
if (this.credentials_url) {
this.fetchLoginCredentials().then(
fetchLoginCredentials().then(
this.autoLogin.bind(this),
this.autoLogin.bind(this)
);
......
......@@ -42144,6 +42144,36 @@ async function finishInitialization() {
}
}
function fetchLoginCredentials() {
new es6_promise_dist_es6_promise_auto__WEBPACK_IMPORTED_MODULE_3___default.a((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
}
function unregisterGlobalEventHandlers() {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
......@@ -42873,34 +42903,6 @@ _converse.initialize = async function (settings, callback) {
});
this.fetchLoginCredentials = () => new es6_promise_dist_es6_promise_auto__WEBPACK_IMPORTED_MODULE_3___default.a((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.credentials_url, true);
xhr.setRequestHeader('Accept', "application/json, text/javascript");
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
const data = JSON.parse(xhr.responseText);
resolve({
'jid': data.jid,
'password': data.password
});
} else {
xhr.onerror();
}
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
});
this.startNewBOSHSession = function () {
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.prebind_url, true);
......@@ -42998,7 +43000,7 @@ _converse.initialize = async function (settings, callback) {
this.autoLogin(credentials);
} else if (this.auto_login) {
if (this.credentials_url) {
this.fetchLoginCredentials().then(this.autoLogin.bind(this), this.autoLogin.bind(this));
fetchLoginCredentials().then(this.autoLogin.bind(this), this.autoLogin.bind(this));
} else if (!this.jid) {
throw new Error("attemptNonPreboundSession: If you use auto_login, " + "you also need to give either a jid value (and if " + "applicable a password) or you need to pass in a URL " + "from where the username and password can be fetched " + "(via credentials_url).");
} else {
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment