1 <%# Copyright (C) The Arvados Authors. All rights reserved.
3 SPDX-License-Identifier: AGPL-3.0 %>
5 <%= javascript_tag do %>
6 function update_visibility() {
7 if (sessionStorage.getItem('link_account_api_token') &&
8 sessionStorage.getItem('link_account_uuid') != '<%= Thread.current[:user].uuid %>')
10 $("#ready-to-link").css({"display": "inherit"});
11 $("#need-login").css({"display": "none"});
13 <% if params[:direction] == "in" %>
14 var user_a = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_username')+", "+sessionStorage.getItem('link_account_uuid')+")";
15 var user_b = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].username%>, <%= Thread.current[:user].uuid%>)";
16 var user_a_is_active = (sessionStorage.getItem('link_account_is_active') == "true");
17 var user_a_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true");
18 var user_b_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>;
20 var user_a = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].username%>, <%= Thread.current[:user].uuid%>)";
21 var user_b = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_username')+", "+sessionStorage.getItem('link_account_uuid')+")";
22 var user_a_is_active = <%= Thread.current[:user].is_active %>;
23 var user_a_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>;
24 var user_b_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true");
27 $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
29 if (!user_a_is_active) {
30 $("#will-link-to").html("<p>Cannot link "+user_b+" to inactive account "+user_a+".</p>");
31 $("#link-account-submit").prop("disabled", true);
32 } else if (user_b_is_admin && !user_a_is_admin) {
33 $("#will-link-to").html("<p>Cannot link admin account "+user_b+" to non-admin account "+user_a+".</p>");
34 $("#link-account-submit").prop("disabled", true);
36 $("#will-link-to").html("<p>Clicking 'Link accounts' will link "+user_b+" created on <%=Thread.current[:user].created_at%> to "+
37 user_a+" created at <b>"+sessionStorage.getItem('link_account_created_at')+"</b>.</p>"+
38 "<p>After linking, logging in as "+user_b+" will log you into the same account as "+user_a+
39 ".</p> <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
42 $("#ready-to-link").css({"display": "none"});
43 $("#need-login").css({"display": "inherit"});
46 sessionStorage.removeItem('link_account_api_token');
47 sessionStorage.removeItem('link_account_uuid');
48 sessionStorage.removeItem('link_account_email');
49 sessionStorage.removeItem('link_account_username');
50 sessionStorage.removeItem('link_account_created_at');
51 sessionStorage.removeItem('link_account_is_active');
52 sessionStorage.removeItem('link_account_is_admin');
55 $(window).on("load", function() {
59 function do_login(dir) {
60 sessionStorage.setItem('link_account_api_token', '<%= Thread.current[:arvados_api_token] %>');
61 sessionStorage.setItem('link_account_email', '<%= Thread.current[:user].email %>');
62 sessionStorage.setItem('link_account_username', '<%= Thread.current[:user].username %>');
63 sessionStorage.setItem('link_account_uuid', '<%= Thread.current[:user].uuid %>');
64 sessionStorage.setItem('link_account_created_at', '<%= Thread.current[:user].created_at %>');
65 sessionStorage.setItem('link_account_is_active', <%= if Thread.current[:user].is_active then "true" else "false" end %>);
66 sessionStorage.setItem('link_account_is_admin', <%= if Thread.current[:user].is_admin then "true" else "false" end %>);
67 window.location.replace('<%=arvados_api_client.arvados_logout_url(return_to: arvados_api_client.arvados_login_url(return_to: "#{strip_token_from_path(request.url)}?direction="))%>'+dir);
70 $(document).on("click", "#link-account-in", function(e) { do_login("in"); });
71 $(document).on("click", "#link-account-out", function(e) { do_login("out"); });
73 $(document).on("click", "#cancel-link-accounts", function() {
74 window.location.replace('/users/link_account?api_token='+$("#new-user-token-input").val());
78 <% if Rails.configuration.Login.LoginCluster.empty? %>
80 <div id="need-login" style="display: none">
82 <p>You are currently logged in as <b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].username%>, <%= Thread.current[:user].uuid %>) created at <b><%= Thread.current[:user].created_at%></b></p>
84 <p>You can link Arvados accounts. After linking, either login will take you to the same account.</p>
87 <% if Thread.current[:user].is_active %>
88 <button class="btn btn-primary" id="link-account-in" style="margin-right: 1em">
89 <i class="fa fa-fw fa-sign-in"></i> Add another login to this account
92 <button class="btn btn-primary" id="link-account-out" style="margin-right: 1em">
93 <i class="fa fa-fw fa-sign-in"></i> Use this login to access another account
99 <div id="ready-to-link" style="display: none">
101 <div id="will-link-to"></div>
103 <%= button_tag "Cancel", class: "btn btn-cancel pull-left", id: "cancel-link-accounts", style: "margin-right: 1em" %>
105 <%= form_tag do |f| %>
106 <input type="hidden" id="new-user-token-input" name="new_user_token" value="" />
107 <input type="hidden" id="new-user-token-input" name="direction" value="<%=params[:direction]%>" />
108 <%= button_tag class: "btn btn-primary", id: "link-account-submit" do %>
109 <i class="fa fa-fw fa-link"></i> Link accounts
117 Self-serve account linking is not supported on this cluster. Please contact your Arvados administrator.