normalize emails
This commit is contained in:
+9
-1
@@ -19,9 +19,11 @@ class User < ApplicationRecord
|
|||||||
|
|
||||||
enum :role, %i[contributor reviewer admin]
|
enum :role, %i[contributor reviewer admin]
|
||||||
|
|
||||||
validates :email, presence: true, uniqueness: true
|
validates :email, presence: true, uniqueness: { case_sensitive: false }
|
||||||
validates :password, length: { minimum: 12 }, if: -> { password.present? }
|
validates :password, length: { minimum: 12 }, if: -> { password.present? }
|
||||||
|
|
||||||
|
before_validation :normalize_email
|
||||||
|
|
||||||
scope :by_role, ->(role) { where(role: role) if role.present? }
|
scope :by_role, ->(role) { where(role: role) if role.present? }
|
||||||
scope :search_email, ->(q) { where("email LIKE ?", "%#{sanitize_sql_like(q)}%") if q.present? }
|
scope :search_email, ->(q) { where("email LIKE ?", "%#{sanitize_sql_like(q)}%") if q.present? }
|
||||||
|
|
||||||
@@ -78,4 +80,10 @@ class User < ApplicationRecord
|
|||||||
return nil if user.nil? || user.remember_token_expired?
|
return nil if user.nil? || user.remember_token_expired?
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def normalize_email
|
||||||
|
self.email = email.downcase.strip if email.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user