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,12 +27,25 @@
c.showLoader(); c.showLoader();
// We gonna retry 3 times to check if yunohost is installed
if (app.isInstalledTry === undefined) {
app.isInstalledTry = 3;
}
c.checkInstall(function(isInstalled) { c.checkInstall(function(isInstalled) {
if (isInstalled) { if (isInstalled) {
c.hideLoader();
// Pass domain to hide form field
c.view('login', { 'domain': window.location.hostname }); c.view('login', { 'domain': window.location.hostname });
} else if (typeof isInstalled === 'undefined') { return;
}
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) { if (app.isInstalledTry > 0) {
app.isInstalledTry--; app.isInstalledTry--;
setTimeout(function() { setTimeout(function() {
@ -40,24 +53,7 @@
}, 5000); }, 5000);
} }
else { else {
// Reset count c.flash('fail', y18n.t('api_not_responding'));
app.isInstalledTry = 3;
// 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();
c.redirect('#/postinstall');
} }
}); });
}); });