Renaming of management validations
This commit is contained in:
34
app/models/verification/management/email.rb
Normal file
34
app/models/verification/management/email.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
class Verification::Management::Email
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :document_type
|
||||
attr_accessor :document_number
|
||||
attr_accessor :email
|
||||
|
||||
validates :document_type, :document_number, presence: true
|
||||
validate :validate_email
|
||||
|
||||
def user
|
||||
@user ||= User.where(email: email).first
|
||||
end
|
||||
|
||||
def user?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def send_email
|
||||
# FIXME
|
||||
# Should assign document_number here?
|
||||
# Should send verification email here?
|
||||
end
|
||||
|
||||
def validate_email
|
||||
if email.blank?
|
||||
errors.add(:email, I18n.t('errors.messages.blank'))
|
||||
elsif email !~ Devise.email_regexp
|
||||
errors.add(:email, I18n.t('errors.messages.invalid'))
|
||||
elsif !user?
|
||||
errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user