17499: Adjust formatting. improve error reporting.
[arvados.git] / apps / workbench / app / views / users / welcome.html.erb
1 <%# Copyright (C) The Arvados Authors. All rights reserved.
2
3 SPDX-License-Identifier: AGPL-3.0 %>
4
5 <% content_for :breadcrumbs do raw '<!-- -->' end %>
6
7 <%= javascript_tag do %>
8       async function controller_password_authenticate(event) {
9         event.preventDefault()
10         document.getElementById('login-authenticate-error').innerHTML = '';
11         const resp = await fetch('<%= "#{Rails.configuration.Services.Controller.ExternalURL}" %>arvados/v1/users/authenticate', {
12           method: 'POST',
13
14           headers: {'Content-Type': 'application/json'},
15           body: JSON.stringify({
16             username: document.getElementById('login-username').value,
17             password: document.getElementById('login-password').value,
18           }),
19         })
20         if (!resp.ok) {
21           const respj = await resp.json()
22           document.getElementById('login-authenticate-error').innerHTML = `<p>${respj.errors[0]}</p>`;
23           return
24         }
25         var redir = document.getElementById('login-return-to').value
26         if (redir.indexOf('?') > 0) {
27           redir += '&'
28         } else {
29           redir += '?'
30         }
31         const respj = await resp.json()
32         document.location = redir + "api_token=v2/" + respj.uuid + "/" + respj.api_token
33       }
34       function clear_authenticate_error() {
35         document.getElementById('login-authenticate-error').innerHTML = "";
36       }
37 <% end %>
38
39 <div class="row">
40   <div class="col-sm-8 col-sm-push-4" style="margin-top: 1em">
41     <div class="well clearfix">
42
43       <%= raw(Rails.configuration.Workbench.WelcomePageHTML) %>
44
45       <% case %>
46       <% when Rails.configuration.Login.Google.Enable %>
47       <% when Rails.configuration.Login.OpenIDConnect.Enable %>
48       <% when Rails.configuration.Login.SSO.Enable %>
49         <div class="pull-right">
50           <%= link_to arvados_api_client.arvados_login_url(return_to: request.url), class: "btn btn-primary" do %>
51           Log in to <%= Rails.configuration.Workbench.SiteName %>
52           <i class="fa fa-fw fa-arrow-circle-right"></i>
53           <% end %>
54         </div>
55       <% when Rails.configuration.Login.PAM.Enable %>
56       <% when Rails.configuration.Login.LDAP.Enable %>
57       <% when Rails.configuration.Login.Test.Enable %>
58         <form id="login-form-tag" onsubmit="controller_password_authenticate(event)">
59           <p>username <input type="text" class="form-control" name="login-username"
60                              value="" id="login-username" style="width: 50%"
61                              oninput="clear_authenticate_error()"></input></p>
62           <p>password <input type="password" class="form-control" name="login-password" value=""
63                              id="login-password" style="width: 50%"
64                              oninput="clear_authenticate_error()"></input></p>
65         <input type="hidden" name="return_to" value="<%= "#{Rails.configuration.Services.Workbench1.ExternalURL}" %>" id="login-return-to">
66         <span style="color: red"><p id="login-authenticate-error"></p></span>
67         <button type="submit" class="btn btn-primary">Login</button>
68         </form>
69       <% end %>
70
71     </div>
72   </div>
73 </div>