Give the remembered signer login its own screen
This commit is contained in:
5 files changed
+82
-28
No files matched your search
@@ -16,7 +16,11 @@ class Users::SessionsController < Devise::SessionsController
|
||||
@nostr_remembered_user = nil
|
||||
end
|
||||
|
||||
super
|
||||
if @nostr_remembered_user.present? && params[:password].blank?
|
||||
render :continue_as
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# POST /resource/sign_in
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<%= render HeaderCompactComponent.new(title: "Log in") %>
|
||||
|
||||
<%= render MainCompactComponent.new do %>
|
||||
<h2 class="mb-2 text-xl font-bold text-gray-900">
|
||||
Continue as <%= @nostr_remembered_user.address %>
|
||||
</h2>
|
||||
<p class="mb-8 text-gray-600">
|
||||
Your remote signer is still connected on this device.
|
||||
</p>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<%= button_to "Continue", nostr_continue_path,
|
||||
method: :post, class: "btn-md btn-blue w-full" %>
|
||||
<%= button_to "Log in as a different account", different_account_nostr_continue_path,
|
||||
method: :post, class: "btn-md btn-gray w-full",
|
||||
data: { turbo_confirm: "This will disconnect your remote signer from this account. Continue?" } %>
|
||||
</div>
|
||||
|
||||
<p class="mt-6 mb-0 text-sm text-gray-600">
|
||||
Logging out normally keeps this device remembered. Use “different account” to disconnect the remote signer.
|
||||
</p>
|
||||
|
||||
<p class="mt-6 mb-0 text-sm">
|
||||
<%= link_to "Use username and password", new_user_session_path(password: 1),
|
||||
class: "text-gray-500 underline" %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -7,29 +7,6 @@
|
||||
<%= render HeaderCompactComponent.new(title: "Log in") %>
|
||||
|
||||
<%= render MainCompactComponent.new do %>
|
||||
<% if @nostr_remembered_user.present? %>
|
||||
<div class="mb-8 rounded-lg border border-emerald-200 bg-emerald-50 p-4">
|
||||
<p class="font-bold text-emerald-900">
|
||||
Continue as @<%= @nostr_remembered_user.cn %>
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-emerald-800">
|
||||
Your remote signer is still connected on this device.
|
||||
</p>
|
||||
|
||||
<div class="mt-4 flex flex-col gap-2 sm:flex-row">
|
||||
<%= button_to "Continue as @#{@nostr_remembered_user.cn}", nostr_continue_path,
|
||||
method: :post, class: "btn-md btn-blue w-full sm:w-auto" %>
|
||||
<%= button_to "Log in as a different account", different_account_nostr_continue_path,
|
||||
method: :post, class: "btn-md btn-gray w-full sm:w-auto",
|
||||
data: { turbo_confirm: "This will disconnect your remote signer from this account. Continue?" } %>
|
||||
</div>
|
||||
|
||||
<p class="mt-3 text-xs text-emerald-800">
|
||||
Logging out normally keeps this device remembered. Use “different account” to disconnect the remote signer.
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_for(resource, as: resource_name, url: session_path(resource_name),
|
||||
data: { turbo: enable_turbo.to_s }) do |f| %>
|
||||
<%= render "devise/shared/error_messages", resource: resource %>
|
||||
@@ -106,4 +83,11 @@
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<% if @nostr_remembered_user.present? %>
|
||||
<p class="mt-6 mb-0 text-sm">
|
||||
<%= link_to "Back to continue as #{@nostr_remembered_user.address}",
|
||||
new_user_session_path, class: "text-gray-500 underline" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -1,8 +1,12 @@
|
||||
<%= render HeaderCompactComponent.new(title: "Continue as @#{@nostr_remembered_user.cn}") %>
|
||||
<%= render HeaderCompactComponent.new(title: "Log in") %>
|
||||
|
||||
<%= render MainCompactComponent.new do %>
|
||||
<div data-controller="nostr-continue"
|
||||
data-nostr-continue-status-url-value="<%= nostr_continue_status_path %>">
|
||||
<h2 class="mb-2 text-xl font-bold text-gray-900">
|
||||
Continue as <%= @nostr_remembered_user.address %>
|
||||
</h2>
|
||||
|
||||
<p class="text-gray-700" data-nostr-continue-target="status">
|
||||
Check your signer app to approve the login…
|
||||
</p>
|
||||
@@ -11,7 +15,7 @@
|
||||
|
||||
<div class="mt-8">
|
||||
<%= button_to "Use a different account", different_account_nostr_continue_path,
|
||||
method: :post, class: "btn-md btn-gray w-full sm:w-auto",
|
||||
method: :post, class: "btn-md btn-gray w-full",
|
||||
data: { turbo_confirm: "This will disconnect your remote signer from this account. Continue?" } %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -42,15 +42,49 @@ RSpec.describe "Users::NostrContinues", type: :request do
|
||||
get new_user_session_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Continue as @#{user.cn}")
|
||||
expect(response.body).to include("Continue as #{user.address}")
|
||||
expect(response.body).to include("Log in as a different account")
|
||||
expect(response.body).to include("Use username and password")
|
||||
expect(response.body).not_to include("user[password]")
|
||||
expect(response.body).not_to include("bg-emerald-50")
|
||||
expect(response.body).not_to include("Log in with a remote signer")
|
||||
end
|
||||
|
||||
it "does not start a sign request just by showing the page" do
|
||||
remember_session
|
||||
|
||||
expect do
|
||||
get new_user_session_path
|
||||
end.not_to change(NostrSignRequest, :count)
|
||||
end
|
||||
|
||||
it "shows the normal login page when password login is requested" do
|
||||
remember_session
|
||||
|
||||
get new_user_session_path(password: 1)
|
||||
|
||||
expect(response.body).to include("user[password]")
|
||||
expect(response.body).to include("Back to continue as #{user.address}")
|
||||
expect(response.body).not_to include("Continue as #{user.address}")
|
||||
end
|
||||
|
||||
it "shows the normal login page without a remembered account" do
|
||||
get new_user_session_path
|
||||
|
||||
expect(response.body).not_to include("Continue as @#{user.cn}")
|
||||
expect(response.body).to include("user[password]")
|
||||
expect(response.body).not_to include("Continue as #{user.address}")
|
||||
end
|
||||
|
||||
it "forgets a remembered account whose public key no longer matches" do
|
||||
remember_session
|
||||
allow_any_instance_of(User).to receive(:nostr_pubkey).and_return("different-pubkey")
|
||||
|
||||
get new_user_session_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("user[password]")
|
||||
expect(response.body).not_to include("Continue as #{user.address}")
|
||||
expect(cookies[:nostr_remember]).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,6 +113,7 @@ RSpec.describe "Users::NostrContinues", type: :request do
|
||||
|
||||
get nostr_continue_page_path
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Continue as #{user.address}")
|
||||
expect(response.body).to include("Check your signer app")
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user