emails: automatically fix typos in email addresses.
Try to automatically fix various kind of typos and common mistakes in email addresses when a user creates a new account. It's common for users to signup with addresses like `name@gmai.com`, which leads to bounces when we try to send the welcome email.
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
class EmailAddress < ApplicationRecord
|
||||
belongs_to :user, inverse_of: :email_address
|
||||
|
||||
validates :address, presence: true, confirmation: true, format: { with: EmailValidator::EMAIL_REGEX }
|
||||
validates :normalized_address, uniqueness: true
|
||||
attribute :address
|
||||
attribute :normalized_address
|
||||
|
||||
validates :address, presence: true, format: { message: "is invalid", with: EmailValidator::EMAIL_REGEX }
|
||||
validates :normalized_address, presence: true, uniqueness: true
|
||||
validates :user_id, uniqueness: true
|
||||
validate :validate_deliverable, on: :deliverable
|
||||
|
||||
@@ -17,6 +20,7 @@ class EmailAddress < ApplicationRecord
|
||||
end
|
||||
|
||||
def address=(value)
|
||||
value = Danbooru::EmailAddress.normalize(value)&.to_s || value
|
||||
self.normalized_address = EmailValidator.normalize(value) || address
|
||||
super
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user