emails: send verification mail when user changes address.
This commit is contained in:
@@ -21,6 +21,7 @@ class EmailsController < ApplicationController
|
||||
|
||||
if @user.errors.none?
|
||||
flash[:notice] = "Email updated"
|
||||
UserMailer.email_change_confirmation(@user).deliver_later
|
||||
respond_with(@user, location: settings_url)
|
||||
else
|
||||
flash[:notice] = @user.errors.full_messages.join("; ")
|
||||
@@ -28,6 +29,15 @@ class EmailsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def verify
|
||||
email_id = Danbooru::MessageVerifier.new(:email_verification_key).verify(params[:email_verification_key])
|
||||
@email_address = EmailAddress.find(email_id)
|
||||
@email_address.update!(is_verified: true)
|
||||
|
||||
flash[:notice] = "Email address verified"
|
||||
redirect_to @email_address.user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_privilege(user)
|
||||
|
||||
@@ -11,4 +11,9 @@ class UserMailer < ApplicationMailer
|
||||
@user = user
|
||||
mail to: @user.email_with_name, subject: "#{Danbooru.config.app_name} password reset request"
|
||||
end
|
||||
|
||||
def email_change_confirmation(user)
|
||||
@user = user
|
||||
mail to: @user.email_with_name, subject: "Confirm your email address"
|
||||
end
|
||||
end
|
||||
|
||||
20
app/views/user_mailer/email_change_confirmation.html.erb
Normal file
20
app/views/user_mailer/email_change_confirmation.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<h2>Hi <%= @user.name %>,</h2>
|
||||
|
||||
<p>
|
||||
You recently changed your email address on <%= Danbooru.config.app_name %>.
|
||||
Click the link below to verify your new email address.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= link_to "Verify email address", verify_user_email_url(@user, email_verification_key: Danbooru::MessageVerifier.new(:email_verification_key).generate(@user.email_address.id)) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you did not recently change your email address on <%= Danbooru.config.app_name %>,
|
||||
you may delete and ignore this email.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -27,6 +27,9 @@
|
||||
<p>
|
||||
<% if @user.email_address.present? %>
|
||||
<%= @user.email_address.address %>
|
||||
<% if !@user.email_address.is_verified %>
|
||||
<em>(unverified)</em>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<em>blank</em>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user