17499: Rewrite javascript to pass phantomJS tests
[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       function controller_password_authenticate(event) {
9         event.preventDefault()
10         document.getElementById('login-authenticate-error').innerHTML = '';
11         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         }).then(function(resp) {
20           if (!resp.ok) {
21             resp.json().then(function(respj) {
22               document.getElementById('login-authenticate-error').innerHTML = `<p>${respj.errors[0]}</p>`;
23             });
24             return;
25            }
26
27            var redir = document.getElementById('login-return-to').value
28            if (redir.indexOf('?') > 0) {
29              redir += '&'
30            } else {
31              redir += '?'
32            }
33            resp.json().then(function(respj) {
34              document.location = redir + "api_token=v2/" + respj.uuid + "/" + respj.api_token;
35            });
36          });
37       }
38       function clear_authenticate_error() {
39         document.getElementById('login-authenticate-error').innerHTML = "";
40       }
41 <% end %>
42
43 <div class="row">
44   <div class="col-sm-8 col-sm-push-4" style="margin-top: 1em">
45     <div class="well clearfix">
46
47       <%= raw(Rails.configuration.Workbench.WelcomePageHTML) %>
48
49       <% case %>
50       <% when Rails.configuration.Login.Google.Enable %>
51       <% when Rails.configuration.Login.OpenIDConnect.Enable %>
52       <% when Rails.configuration.Login.SSO.Enable %>
53         <div class="pull-right">
54           <%= link_to arvados_api_client.arvados_login_url(return_to: request.url), class: "btn btn-primary" do %>
55           Log in to <%= Rails.configuration.Workbench.SiteName %>
56           <i class="fa fa-fw fa-arrow-circle-right"></i>
57           <% end %>
58         </div>
59       <% when Rails.configuration.Login.PAM.Enable %>
60       <% when Rails.configuration.Login.LDAP.Enable %>
61       <% when Rails.configuration.Login.Test.Enable %>
62         <form id="login-form-tag" onsubmit="controller_password_authenticate(event)">
63           <p>username <input type="text" class="form-control" name="login-username"
64                              value="" id="login-username" style="width: 50%"
65                              oninput="clear_authenticate_error()"></input></p>
66           <p>password <input type="password" class="form-control" name="login-password" value=""
67                              id="login-password" style="width: 50%"
68                              oninput="clear_authenticate_error()"></input></p>
69         <input type="hidden" name="return_to" value="<%= "#{Rails.configuration.Services.Workbench1.ExternalURL}" %>" id="login-return-to">
70         <span style="color: red"><p id="login-authenticate-error"></p></span>
71         <button type="submit" class="btn btn-primary">Login</button>
72         </form>
73       <% end %>
74
75     </div>
76   </div>
77 </div>