mirror of
https://github.com/neocities/neocities.git
synced 2025-07-22 18:46:07 +02:00
what's this? is this password reset???
This commit is contained in:
parent
72947b6606
commit
1e1051fd36
8 changed files with 104 additions and 2 deletions
51
app.rb
51
app.rb
|
@ -367,6 +367,57 @@ post '/admin/mark_nsfw' do
|
|||
redirect '/admin'
|
||||
end
|
||||
|
||||
get '/password_reset' do
|
||||
slim :'password_reset'
|
||||
end
|
||||
|
||||
post '/send_password_reset' do
|
||||
site = Site[email: params[:email]]
|
||||
|
||||
if site
|
||||
site.update password_reset_token: token
|
||||
|
||||
token = SecureRandom.uuid.gsub('-', '')
|
||||
|
||||
body = <<-EOT
|
||||
Hello! This is the NeoCities cat, and I have received a password reset request for your e-mail address. Purrrr.
|
||||
|
||||
Go to this URL to reset your password: http://neocities.org/password_reset_confirm?code=#{token}
|
||||
|
||||
If you didn't request this reset, 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({
|
||||
to: params[:email],
|
||||
subject: '[NeoCities] Password Reset',
|
||||
body: body
|
||||
})
|
||||
end
|
||||
|
||||
flash[:success] = 'If your email was valid (and used by a site), the NeoCities Cat will send an e-mail to your account with password reset instructions.'
|
||||
redirect '/'
|
||||
end
|
||||
|
||||
get '/password_reset_confirm' do
|
||||
site = Site[password_reset_token: params[:token]]
|
||||
|
||||
if site
|
||||
site.password = params[:token]
|
||||
site.save
|
||||
|
||||
flash[:success] = 'Your password has been changed to the token sent in your e-mail. Please login and change your password in the settings page as soon as possible.'
|
||||
else
|
||||
flash[:error] = 'Could not find a site with this token.'
|
||||
end
|
||||
|
||||
redirect '/'
|
||||
end
|
||||
|
||||
def require_admin
|
||||
redirect '/' unless signed_in? && current_site.is_admin
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue