[UNSTABLE] Install email send hooks into Users::Update
parent
92108f6742
commit
5cb8e75e47
|
@ -3,7 +3,6 @@ class UserMailer < ApplicationMailer
|
|||
@user = user
|
||||
@user_name = user.name
|
||||
@the_url = "http:" + $API_URL + "/verify?token=" + user.confirmation_token
|
||||
throw "Bad registration?" unless @the_url.present?
|
||||
mail(to: @user.email, subject: 'Welcome to The FarmBot Web App!')
|
||||
end
|
||||
|
||||
|
@ -13,4 +12,11 @@ class UserMailer < ApplicationMailer
|
|||
@host = $API_URL
|
||||
mail(to: @user.email, subject: 'FarmBot Password Reset Instructions')
|
||||
end
|
||||
|
||||
def email_update(user)
|
||||
@user = user
|
||||
@host = $API_URL
|
||||
raise "TODO: This."
|
||||
mail(to: @user.email, subject: 'FarmBot Email Update Instructions')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,11 @@ class User < ApplicationRecord
|
|||
before_validation :set_defaults
|
||||
|
||||
def set_defaults
|
||||
self.confirmation_token ||= SecureRandom.uuid
|
||||
self.confirmation_token ||= self.reset_confirmation_token
|
||||
end
|
||||
|
||||
def reset_confirmation_token
|
||||
self.confirmation_token = SecureRandom.uuid
|
||||
end
|
||||
|
||||
def must_consent?
|
||||
|
|
|
@ -20,15 +20,18 @@ module Users
|
|||
end
|
||||
|
||||
def execute
|
||||
maybe_update_email
|
||||
update_email if email.present?
|
||||
user.update_attributes!(inputs.except(:user, :email))
|
||||
user.reload
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def maybe_update_email
|
||||
raise "TODO"
|
||||
def update_email
|
||||
user.reset_confirmation_token
|
||||
user.unconfirmed_email = email
|
||||
user.save!
|
||||
UserMailer.email_update(user).deliver_later
|
||||
end
|
||||
|
||||
def confirm_new_password
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
...
|
Loading…
Reference in New Issue