Set unique_email upon User creation
This commit is contained in:
parent
4052329ca4
commit
c3bc1c08b9
@ -80,6 +80,7 @@ class User < ApplicationRecord
|
|||||||
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }
|
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }
|
||||||
|
|
||||||
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
||||||
|
validates :unique_email, uniqueness: true
|
||||||
validates_with BlacklistedEmailValidator, on: :create
|
validates_with BlacklistedEmailValidator, on: :create
|
||||||
validates_with EmailMxValidator, if: :validate_email_dns?
|
validates_with EmailMxValidator, if: :validate_email_dns?
|
||||||
validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create
|
validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create
|
||||||
@ -95,6 +96,7 @@ class User < ApplicationRecord
|
|||||||
scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) }
|
scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) }
|
||||||
|
|
||||||
before_validation :sanitize_languages
|
before_validation :sanitize_languages
|
||||||
|
before_validation :set_unique_email
|
||||||
before_create :set_approved
|
before_create :set_approved
|
||||||
|
|
||||||
# This avoids a deprecation warning from Rails 5.1
|
# This avoids a deprecation warning from Rails 5.1
|
||||||
@ -347,4 +349,10 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_unique_email
|
||||||
|
user, domain = self.email.split('@')
|
||||||
|
user = user.split('+').first
|
||||||
|
user = user.gsub('.', '') if domain == 'gmail.com'
|
||||||
|
self.unique_email = "#{user}@#{domain}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user