1 <%= javascript_tag do %>
2 function update_visibility() {
3 if (sessionStorage.getItem('link_account_api_token') &&
4 sessionStorage.getItem('link_account_uuid') != '<%= Thread.current[:user].uuid %>')
6 $("#ready-to-link").css({"display": "inherit"});
7 $("#need-login").css({"display": "none"});
9 <% if params[:direction] == "in" %>
10 var user_a = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_uuid')+")";
11 var user_b = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>)";
12 var user_a_is_active = (sessionStorage.getItem('link_account_is_active') == "true");
13 var user_a_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true");
14 var user_b_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>;
16 var user_a = "<b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>)";
17 var user_b = "<b>"+sessionStorage.getItem('link_account_email')+"</b> ("+sessionStorage.getItem('link_account_uuid')+")";
18 var user_a_is_active = <%= Thread.current[:user].is_active %>;
19 var user_a_is_admin = <%=if Thread.current[:user].is_admin then "true" else "false" end %>;
20 var user_b_is_admin = (sessionStorage.getItem('link_account_is_admin') == "true");
23 $("#new-user-token-input").val(sessionStorage.getItem('link_account_api_token'));
25 if (!user_a_is_active) {
26 $("#will-link-to").html("<p>Cannot link "+user_b+" to inactive account "+user_a+".</p>");
27 $("#link-account-submit").prop("disabled", true);
28 } else if (user_b_is_admin && !user_a_is_admin) {
29 $("#will-link-to").html("<p>Cannot link admin account "+user_b+" to non-admin account "+user_a+".</p>");
30 $("#link-account-submit").prop("disabled", true);
32 $("#will-link-to").html("<p>Clicking 'Link accounts' will link "+user_b+" created on <%=Thread.current[:user].created_at%> to "+
33 user_a+" created at <b>"+sessionStorage.getItem('link_account_created_at')+"</b>.</p>"+
34 "<p>After linking, logging in as "+user_b+" will log you into the same account as "+user_a+
35 ".</p> <p>Any objects owned by "+user_b+" will be transferred to "+user_a+".</p>");
38 $("#ready-to-link").css({"display": "none"});
39 $("#need-login").css({"display": "inherit"});
42 sessionStorage.removeItem('link_account_api_token');
43 sessionStorage.removeItem('link_account_uuid');
44 sessionStorage.removeItem('link_account_email');
45 sessionStorage.removeItem('link_account_created_at');
46 sessionStorage.removeItem('link_account_is_active');
47 sessionStorage.removeItem('link_account_is_admin');
50 $(window).on("load", function() {
54 function do_login(dir) {
55 sessionStorage.setItem('link_account_api_token', '<%= Thread.current[:arvados_api_token] %>');
56 sessionStorage.setItem('link_account_email', '<%= Thread.current[:user].email %>');
57 sessionStorage.setItem('link_account_uuid', '<%= Thread.current[:user].uuid %>');
58 sessionStorage.setItem('link_account_created_at', '<%= Thread.current[:user].created_at %>');
59 sessionStorage.setItem('link_account_is_active', <%= if Thread.current[:user].is_active then "true" else "false" end %>);
60 sessionStorage.setItem('link_account_is_admin', <%= if Thread.current[:user].is_admin then "true" else "false" end %>);
61 window.location.replace('<%=arvados_api_client.arvados_login_url(return_to: "#{strip_token_from_path(request.url)}?direction=")%>'+dir);
64 $(document).on("click", "#link-account-in", function(e) { do_login("in"); });
65 $(document).on("click", "#link-account-out", function(e) { do_login("out"); });
67 $(document).on("click", "#cancel-link-accounts", function() {
68 window.location.replace('/users/link_account?api_token='+$("#new-user-token-input").val());
72 <div id="need-login" style="display: none">
74 <p>You are currently logged in as <b><%= Thread.current[:user].email %></b> (<%= Thread.current[:user].uuid%>) created at <b><%= Thread.current[:user].created_at%></b></p>
76 <p>You can link Arvados accounts. After linking, either login will take you to the same account.</p>
79 <% if Thread.current[:user].is_active %>
80 <button class="btn btn-primary" id="link-account-in" style="margin-right: 1em">
81 <i class="fa fa-fw fa-sign-in"></i> Add another login to this account
84 <button class="btn btn-primary" id="link-account-out" style="margin-right: 1em">
85 <i class="fa fa-fw fa-sign-in"></i> Use this login to access another account
91 <div id="ready-to-link" style="display: none">
93 <div id="will-link-to"></div>
95 <%= button_tag "Cancel", class: "btn btn-cancel pull-left", id: "cancel-link-accounts", style: "margin-right: 1em" %>
97 <%= form_tag do |f| %>
98 <input type="hidden" id="new-user-token-input" name="new_user_token" value="" />
99 <input type="hidden" id="new-user-token-input" name="direction" value="<%=params[:direction]%>" />
100 <%= button_tag class: "btn btn-primary", id: "link-account-submit" do %>
101 <i class="fa fa-fw fa-link"></i> Link accounts