Simplify /login route code...

This commit is contained in:
Alexandre Aubin 2019-10-19 03:43:33 +02:00
parent 72b4e66a7f
commit e16e822a89

View file

@ -27,37 +27,33 @@
c.showLoader();
// We gonna retry 3 times to check if yunohost is installed
if (app.isInstalledTry === undefined) {
app.isInstalledTry = 3;
}
c.checkInstall(function(isInstalled) {
if (isInstalled) {
c.hideLoader();
// Pass domain to hide form field
c.view('login', { 'domain': window.location.hostname });
} else if (typeof isInstalled === 'undefined') {
if (app.isInstalledTry > 0) {
app.isInstalledTry--;
setTimeout(function() {
c.redirect('#/');
}, 5000);
}
else {
// Reset count
app.isInstalledTry = 3;
return;
}
// API is not responding after 3 try
$( document ).ajaxError(function( event, request, settings ) {
// Display error if status != 200.
// .ajaxError fire even with status code 200 because json is sometimes not valid.
if (request.status !== 200) c.flash('fail', y18n.t('api_not_responding', [request.status+' '+request.statusText] ));
// Unbind directly
$(document).off('ajaxError');
});
c.hideLoader();
}
} else {
c.hideLoader();
if (typeof isInstalled !== 'undefined') {
c.redirect('#/postinstall');
return;
}
// If the retry counter is still up, retry this function 5 sec
// later
if (app.isInstalledTry > 0) {
app.isInstalledTry--;
setTimeout(function() {
c.redirect('#/');
}, 5000);
}
else {
c.flash('fail', y18n.t('api_not_responding'));
}
});
});