Let user remove nostr pubkey from account
This commit is contained in:
		
							parent
							
								
									49de4007ab
								
							
						
					
					
						commit
						e8bbe6c713
					
				| @ -14,6 +14,10 @@ | ||||
|     @apply py-1 px-2 text-sm; | ||||
|   } | ||||
| 
 | ||||
|   .btn-outline { | ||||
|     @apply border-2 border-gray-100 hover:bg-gray-100; | ||||
|   } | ||||
| 
 | ||||
|   .btn-icon { | ||||
|     @apply px-3; | ||||
|   } | ||||
|  | ||||
| @ -88,6 +88,15 @@ class SettingsController < ApplicationController | ||||
|     http_status :unprocessable_entity and return | ||||
|   end | ||||
| 
 | ||||
|   # DELETE /settings/nostr_pubkey | ||||
|   def remove_nostr_pubkey | ||||
|     current_user.update! nostr_pubkey: nil | ||||
| 
 | ||||
|     redirect_to setting_path(:experiments), flash: { | ||||
|       success: 'Public key removed from account' | ||||
|     } | ||||
|   end | ||||
| 
 | ||||
|   private | ||||
| 
 | ||||
|     def set_main_nav_section | ||||
|  | ||||
| @ -6,12 +6,37 @@ | ||||
|        data-settings--nostr-pubkey-shared-secret-value="<%= session[:shared_secret] %>" | ||||
|        data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>"> | ||||
| 
 | ||||
|     <p class="mt-2 <%= current_user.nostr_pubkey.present? ? "" : "hidden" %>"> | ||||
|       <input type="text" class="w-full" value="<%= current_user.nostr_pubkey %>" | ||||
|              data-settings--nostr-pubkey-target="pubkeyBech32Input" disabled /> | ||||
|     <p class="<%= current_user.nostr_pubkey.present? ? '' : 'hidden' %> mt-2 flex gap-1"> | ||||
|       <input type="text" value="<%= current_user.nostr_pubkey %>" disabled | ||||
|              data-settings--nostr-pubkey-target="pubkeyBech32Input" | ||||
|              name="nostr_public_key" class="relative grow" /> | ||||
|       <%= link_to nostr_pubkey_settings_path, | ||||
|             class: 'btn-md btn-outline text-red-700 relative shrink-0', | ||||
|             data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' } do %> | ||||
|         Remove | ||||
|       <% end %> | ||||
|     </p> | ||||
| 
 | ||||
|     <% unless current_user.nostr_pubkey.present? %> | ||||
|     <% if current_user.nostr_pubkey.present? %> | ||||
|     <div class="rounded-md bg-blue-50 p-4"> | ||||
|       <div class="flex"> | ||||
|         <div class="flex-shrink-0"> | ||||
|           <svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> | ||||
|             <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" /> | ||||
|           </svg> | ||||
|         </div> | ||||
|         <div class="ml-3 flex-1"> | ||||
|           <p class="text-sm text-blue-800"> | ||||
|             Your user address <strong><%= current_user.address %></strong> is | ||||
|             also a Nostr address now. Use your favorite Nostr app, or for | ||||
|             example <a href="http://metadata.nostr.com" target="_blank" | ||||
|               class="underline">metadata.nostr.com</a>, to add this | ||||
|             <strong>NIP-05</strong> address to your public profile. | ||||
|           </p> | ||||
|         </div> | ||||
|       </div> | ||||
|     </div> | ||||
|     <% else %> | ||||
|     <p class="my-4"> | ||||
|       If you use any apps on the Nostr network, you can verify your public key | ||||
|       with us in order to enable Nostr-specific features for your account. | ||||
| @ -51,12 +76,14 @@ | ||||
|       </div> | ||||
|     </div> | ||||
| 
 | ||||
|     <% unless current_user.nostr_pubkey.present? %> | ||||
|     <p class="mt-8"> | ||||
|       <button class="btn-md btn-gray" disabled | ||||
|       <button class="btn-md btn-gray w-full sm:w-auto" disabled | ||||
|               data-settings--nostr-pubkey-target="setPubkey" | ||||
|               data-action="settings--nostr-pubkey#setPubkey"> | ||||
|         Get public key from browser extension | ||||
|       </button> | ||||
|     </p> | ||||
|     <% end %> | ||||
|   </div> | ||||
| </section> | ||||
|  | ||||
| @ -33,6 +33,7 @@ Rails.application.routes.draw do | ||||
|       post 'update_email' | ||||
|       post 'reset_password' | ||||
|       post 'set_nostr_pubkey' | ||||
|       delete 'nostr_pubkey', to: 'settings#remove_nostr_pubkey' | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|  | ||||
| @ -19,4 +19,22 @@ RSpec.describe 'Experimental Settings', type: :feature do | ||||
|     #   worth it for now | ||||
|     # end | ||||
|   end | ||||
| 
 | ||||
|   context "With pubkey configured" do | ||||
|     before do | ||||
|       user.update! nostr_pubkey: "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3" | ||||
|     end | ||||
| 
 | ||||
|     scenario 'Remove nostr pubkey from account' do | ||||
|       visit settings_experiments_path | ||||
|       expect(page).to have_field("nostr_public_key", | ||||
|         with: "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3", | ||||
|         disabled: true) | ||||
| 
 | ||||
|       click_link "Remove" | ||||
|       expect(page).to_not have_field("nostr_public_key") | ||||
|       expect(page).to have_content("verify your public key") | ||||
|       expect(user.reload.nostr_pubkey).to be_nil | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user