Merge branch '21030-update-perm-cte' refs #21030
[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.PAM.Enable,
51               Rails.configuration.Login.LDAP.Enable,
52               Rails.configuration.Login.Test.Enable %>
53         <form id="login-form-tag" onsubmit="controller_password_authenticate(event)">
54           <p>username <input type="text" class="form-control" name="login-username"
55                              value="" id="login-username" style="width: 50%"
56                              oninput="clear_authenticate_error()"></input></p>
57           <p>password <input type="password" class="form-control" name="login-password" value=""
58                              id="login-password" style="width: 50%"
59                              oninput="clear_authenticate_error()"></input></p>
60         <input type="hidden" name="return_to" value="<%= params[:return_to] || "#{Rails.configuration.Services.Workbench1.ExternalURL}" %>" id="login-return-to">
61         <span style="color: red"><p id="login-authenticate-error"></p></span>
62         <button type="submit" class="btn btn-primary">Log in</button>
63         </form>
64       <% else %>
65         <div class="pull-right">
66           <%= link_to arvados_api_client.arvados_login_url(return_to: request.url), class: "btn btn-primary" do %>
67           Log in to <%= Rails.configuration.Workbench.SiteName %>
68           <i class="fa fa-fw fa-arrow-circle-right"></i>
69           <% end %>
70         </div>
71       <% end %>
72
73     </div>
74   </div>
75 </div>