mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +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 :email, presence: true, if: -> { country.iso != 'EE' }
|
||||||
validates :registrar, presence: true, if: -> { !admin }
|
validates :registrar, presence: true, if: -> { !admin }
|
||||||
|
|
||||||
|
validate :validate_identity_code
|
||||||
|
|
||||||
before_save -> { self.registrar = nil if admin? }
|
before_save -> { self.registrar = nil if admin? }
|
||||||
|
|
||||||
attr_accessor :registrar_typeahead
|
attr_accessor :registrar_typeahead
|
||||||
|
@ -27,4 +29,12 @@ class User < ActiveRecord::Base
|
||||||
def registrar_typeahead
|
def registrar_typeahead
|
||||||
@registrar_typeahead || registrar || nil
|
@registrar_typeahead || registrar || nil
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -170,6 +170,7 @@ en:
|
||||||
password:
|
password:
|
||||||
blank: 'Password is missing'
|
blank: 'Password is missing'
|
||||||
identity_code:
|
identity_code:
|
||||||
|
invalid: 'Identity code is invalid'
|
||||||
blank: 'Identity code is missing'
|
blank: 'Identity code is missing'
|
||||||
taken: 'Identity code already exists'
|
taken: 'Identity code already exists'
|
||||||
email:
|
email:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue