36b457af0a14ba820d588200ea67184145c09fa8
[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       // document.getElementById('login-form-tag').
35 <% end %>
36
37 <div class="row">
38   <div class="col-sm-8 col-sm-push-4" style="margin-top: 1em">
39     <div class="well clearfix">
40
41       <%= raw(Rails.configuration.Workbench.WelcomePageHTML) %>
42
43       <% case %>
44       <% when Rails.configuration.Login.Google.Enable %>
45       <% when Rails.configuration.Login.OpenIDConnect.Enable %>
46       <% when Rails.configuration.Login.SSO.Enable %>
47         <div class="pull-right">
48           <%= link_to arvados_api_client.arvados_login_url(return_to: request.url), class: "btn btn-primary" do %>
49           Log in to <%= Rails.configuration.Workbench.SiteName %>
50           <i class="fa fa-fw fa-arrow-circle-right"></i>
51           <% end %>
52         </div>
53       <% when Rails.configuration.Login.PAM.Enable %>
54       <% when Rails.configuration.Login.LDAP.Enable %>
55       <% when Rails.configuration.Login.Test.Enable %>
56         <form id="login-form-tag" onsubmit="controller_password_authenticate(event)">
57         <p>username <input type="text" class="form-control" name="login-username" value="" id="login-username" style="width: 50%"></input></p>
58         <p>password <input type="password" class="form-control" name="login-password" value="" id="login-password" style="width: 50%"></input></p>
59         <input type="hidden" name="return_to" value="<%= "#{Rails.configuration.Services.Workbench1.ExternalURL}" %>" id="login-return-to">
60         <p id="login-authenticate-error"></p>
61         <button type="submit" class="btn btn-primary">Login</button>
62         </form>
63       <% end %>
64
65     </div>
66   </div>
67 </div>