Generate auth info automatically

This commit is contained in:
Martin Lensment 2014-09-04 10:26:01 +03:00
parent aa56fa3160
commit 6352ed340f
4 changed files with 25 additions and 7 deletions

View file

@ -99,8 +99,7 @@ module Epp::DomainsHelper
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
period_unit: Domain.parse_period_unit_from_frame(parsed_frame) || 'y',
valid_from: Date.today,
valid_to: valid_to,
auth_info: @ph[:authInfo][:pw]
valid_to: valid_to
}
end

View file

@ -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