mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
username lookup tool
This commit is contained in:
parent
fd3a7ccabc
commit
05e5b3998b
4 changed files with 112 additions and 3 deletions
39
app/index.rb
39
app/index.rb
|
@ -82,3 +82,42 @@ end
|
|||
get '/thankyou' do
|
||||
erb :'thankyou'
|
||||
end
|
||||
|
||||
get '/forgot_username' do
|
||||
erb :'forgot_username'
|
||||
end
|
||||
|
||||
post '/forgot_username' do
|
||||
if params[:email].blank?
|
||||
flash[:error] = 'Cannot use an empty email address!'
|
||||
redirect '/forgot_username'
|
||||
end
|
||||
|
||||
sites = Site.where(email: params[:email]).all
|
||||
|
||||
sites.each do |site|
|
||||
body = <<-EOT
|
||||
Hello! This is the Neocities cat, and I have received a username lookup request using this email address.
|
||||
|
||||
Your username is #{site.username}
|
||||
|
||||
If you didn't request this, you can ignore it. Or hide under a bed. Or take a nap. Your call.
|
||||
|
||||
Meow,
|
||||
the Neocities Cat
|
||||
EOT
|
||||
|
||||
body.strip!
|
||||
|
||||
EmailWorker.perform_async({
|
||||
from: 'web@neocities.org',
|
||||
to: params[:email],
|
||||
subject: '[Neocities] Username lookup',
|
||||
body: body
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
flash[:success] = 'If your email was valid, the Neocities Cat will send an e-mail with your username in it.'
|
||||
redirect '/'
|
||||
end
|
||||
|
|
|
@ -63,4 +63,41 @@ describe '/' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'username lookup' do
|
||||
before do
|
||||
@site = Fabricate :site
|
||||
Capybara.reset_sessions!
|
||||
EmailWorker.jobs.clear
|
||||
|
||||
visit '/signin'
|
||||
click_link 'I forgot my username.'
|
||||
end
|
||||
|
||||
it 'works for valid email' do
|
||||
page.current_url.must_match /\/forgot_username$/
|
||||
fill_in :email, with: @site.email
|
||||
click_button 'Find username'
|
||||
URI.parse(page.current_url).path.must_equal '/'
|
||||
page.must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it'
|
||||
email_args = EmailWorker.jobs.first['args'].first
|
||||
email_args['to'].must_equal @site.email
|
||||
email_args['subject'].must_match /username lookup/i
|
||||
email_args['body'].must_match /your username is #{@site.username}/i
|
||||
end
|
||||
|
||||
it 'fails silently for unknown email' do
|
||||
fill_in :email, with: 'N-O-P-E@example.com'
|
||||
click_button 'Find username'
|
||||
URI.parse(page.current_url).path.must_equal '/'
|
||||
page.must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it'
|
||||
EmailWorker.jobs.length.must_equal 0
|
||||
end
|
||||
|
||||
it 'fails for no input' do
|
||||
click_button 'Find username'
|
||||
URI.parse(page.current_url).path.must_equal '/forgot_username'
|
||||
page.must_have_content 'Cannot use an empty email address'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
31
views/forgot_username.erb
Normal file
31
views/forgot_username.erb
Normal file
|
@ -0,0 +1,31 @@
|
|||
<div class="header-Outro">
|
||||
<div class="row content single-Col txt-Center">
|
||||
<h1>Forgot Username</h1>
|
||||
<h3 class="subtitle"></h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content txt-Center single-Col misc-page">
|
||||
<% if flash.keys.length > 0 %>
|
||||
<div class="alert alert-block">
|
||||
<p>
|
||||
<% flash.keys.select {|s| s == :error}.each do |key| %>
|
||||
<%= flash[key] %>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<p>If you forgot your sitename (AKA username), you can have it emailed to you here.</p>
|
||||
|
||||
<p>Keep in mind that we cannot help you locate your sitename without a valid email address, and we don't disclose whether an email address exists in our system. This is for security and privacy reasons.</p>
|
||||
|
||||
<form method="POST" action="/forgot_username" class="content">
|
||||
<input name="csrf_token" type="hidden" value="<%= csrf_token %>">
|
||||
<fieldset>
|
||||
<label for="email">Enter your email</label>
|
||||
<input name="email" type="text" placeholder="email@address.com" class="input-Area" autocapitalize="off" autocorrect="off" value="<%= flash[:email] %>" style="width: 290px">
|
||||
</fieldset>
|
||||
<input class="btn-Action" type="submit" value="Find username">
|
||||
</form>
|
||||
</div>
|
|
@ -32,6 +32,8 @@
|
|||
<a href="/#new" title="Sign me up!">I don't have an account yet.</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/password_reset" title="What did I huh?">I forgot my password.</a>
|
||||
<a href="/password_reset" title="You should use a password manager like LastPass, it will change your life.">I forgot my password.</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/forgot_username" title="Seriously?">I forgot my username.</a>
|
||||
</div>
|
Loading…
Add table
Reference in a new issue