From 72b4e66a7fb72640a028b2449c6a1f2615dea9d6 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 19 Oct 2019 03:33:10 +0200 Subject: [PATCH] Simplify postinstall code... --- src/js/yunohost/controllers/postinstall.js | 56 ++++++++++++---------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/js/yunohost/controllers/postinstall.js b/src/js/yunohost/controllers/postinstall.js index b2c5cc05..6e99a520 100644 --- a/src/js/yunohost/controllers/postinstall.js +++ b/src/js/yunohost/controllers/postinstall.js @@ -68,35 +68,43 @@ // Execute post-installation app.post('#/postinstall', function (c) { - if (c.params['password'] === '' || c.params['confirmation'] === '') { + + var password = c.params['password']; + var confirmation = c.params['confirmation']; + var domain = c.params['domain'].toLowerCase(); + + // Check password ain't empty + if (password === '' || confirmation === '') { c.flash('fail', y18n.t('password_empty')); + return; } - else if (c.params['password'] == c.params['confirmation']) { - if (c.params['domain'] === '') { - c.flash('fail', y18n.t('error_select_domain')); - c.redirect_to('#/postinstall/domain', {slide: false}); - } else { - var params = { - domain: c.params['domain'].toLowerCase() - }; - } - c.confirm( - y18n.t('postinstall'), - y18n.t('confirm_postinstall', [c.params['domain']]), - function(){ - params.password = c.params['password']; - - store.set('url', window.location.hostname +'/yunohost/api'); - store.set('user', 'admin'); - c.api('POST', '/postinstall', params, function(data) { - c.redirect_to('#/login'); - }); - } - ); - } else { + // Check password matches confirmation + if (password !== confirmation) { c.flash('fail', y18n.t('passwords_dont_match')); + return; } + + // Check domain ain't empty... + if (domain === '') { + c.flash('fail', y18n.t('error_select_domain')); + c.redirect_to('#/postinstall/domain', {slide: false}); + return; + } + + // Ask confirmation to the user + c.confirm( + y18n.t('postinstall'), + y18n.t('confirm_postinstall', [c.params['domain']]), + // Start the actual postinstall process + function(){ + store.set('url', window.location.hostname +'/yunohost/api'); + store.set('user', 'admin'); + c.api('POST', '/postinstall', {domain: domain, password: password}, function() { + c.redirect_to('#/login'); + }); + } + ); }); })();