mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 07:52:04 +02:00
Generate auth info automatically
This commit is contained in:
parent
aa56fa3160
commit
6352ed340f
4 changed files with 25 additions and 7 deletions
|
@ -33,6 +33,8 @@ class Domain < ActiveRecord::Base
|
|||
delegate :code, to: :owner_contact, prefix: true
|
||||
delegate :name, to: :registrar, prefix: true
|
||||
|
||||
before_create :generate_auth_info
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
validates :period, numericality: { only_integer: true }
|
||||
validates :name, :owner_contact, presence: true
|
||||
|
@ -313,6 +315,12 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
## SHARED
|
||||
|
||||
def generate_auth_info
|
||||
begin
|
||||
self.auth_info = SecureRandom.hex
|
||||
end while self.class.exists?(auth_info: auth_info)
|
||||
end
|
||||
|
||||
# For domain transfer
|
||||
def authenticate(pw)
|
||||
errors.add(:auth_info, { msg: errors.generate_message(:auth_info, :wrong_pw) }) if pw != auth_info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue