mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Validate identity code on user
This commit is contained in:
parent
b403cbebcd
commit
9f878f219c
2 changed files with 11 additions and 0 deletions
|
@ -16,6 +16,8 @@ class User < ActiveRecord::Base
|
|||
validates :email, presence: true, if: -> { country.iso != 'EE' }
|
||||
validates :registrar, presence: true, if: -> { !admin }
|
||||
|
||||
validate :validate_identity_code
|
||||
|
||||
before_save -> { self.registrar = nil if admin? }
|
||||
|
||||
attr_accessor :registrar_typeahead
|
||||
|
@ -27,4 +29,12 @@ class User < ActiveRecord::Base
|
|||
def registrar_typeahead
|
||||
@registrar_typeahead || registrar || nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_identity_code
|
||||
return unless identity_code.present?
|
||||
code = Isikukood.new(identity_code)
|
||||
errors.add(:identity_code, :invalid) unless code.valid?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -170,6 +170,7 @@ en:
|
|||
password:
|
||||
blank: 'Password is missing'
|
||||
identity_code:
|
||||
invalid: 'Identity code is invalid'
|
||||
blank: 'Identity code is missing'
|
||||
taken: 'Identity code already exists'
|
||||
email:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue