From c10061b6de6b85e7c445723a0f32a717ee76fe85 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 14 May 2021 16:19:39 -0400 Subject: [PATCH] 17499: Rewrite javascript to pass phantomJS tests Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../app/views/users/welcome.html.erb | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/apps/workbench/app/views/users/welcome.html.erb b/apps/workbench/app/views/users/welcome.html.erb index 2842cd8848..8d3e42e4e3 100644 --- a/apps/workbench/app/views/users/welcome.html.erb +++ b/apps/workbench/app/views/users/welcome.html.erb @@ -5,10 +5,10 @@ SPDX-License-Identifier: AGPL-3.0 %> <% content_for :breadcrumbs do raw '' end %> <%= javascript_tag do %> - async function controller_password_authenticate(event) { + function controller_password_authenticate(event) { event.preventDefault() document.getElementById('login-authenticate-error').innerHTML = ''; - const resp = await fetch('<%= "#{Rails.configuration.Services.Controller.ExternalURL}" %>arvados/v1/users/authenticate', { + fetch('<%= "#{Rails.configuration.Services.Controller.ExternalURL}" %>arvados/v1/users/authenticate', { method: 'POST', headers: {'Content-Type': 'application/json'}, @@ -16,20 +16,24 @@ SPDX-License-Identifier: AGPL-3.0 %> username: document.getElementById('login-username').value, password: document.getElementById('login-password').value, }), - }) - if (!resp.ok) { - const respj = await resp.json() - document.getElementById('login-authenticate-error').innerHTML = `

${respj.errors[0]}

`; - return - } - var redir = document.getElementById('login-return-to').value - if (redir.indexOf('?') > 0) { - redir += '&' - } else { - redir += '?' - } - const respj = await resp.json() - document.location = redir + "api_token=v2/" + respj.uuid + "/" + respj.api_token + }).then(function(resp) { + if (!resp.ok) { + resp.json().then(function(respj) { + document.getElementById('login-authenticate-error').innerHTML = `

${respj.errors[0]}

`; + }); + return; + } + + var redir = document.getElementById('login-return-to').value + if (redir.indexOf('?') > 0) { + redir += '&' + } else { + redir += '?' + } + resp.json().then(function(respj) { + document.location = redir + "api_token=v2/" + respj.uuid + "/" + respj.api_token; + }); + }); } function clear_authenticate_error() { document.getElementById('login-authenticate-error').innerHTML = ""; -- 2.30.2