Story#108091488 - Seems that now reserved domains will be in better table

This commit is contained in:
Vladimir Krylov 2016-01-05 14:08:51 +02:00
parent 3c33a44f38
commit 6415bfae38
4 changed files with 34 additions and 16 deletions

View file

@ -2,24 +2,27 @@ class ReservedDomain < ActiveRecord::Base
include Versions # version/reserved_domain_version.rb
before_save :fill_empty_passwords
def fill_empty_passwords
return unless names
names.each { |k, v| names[k] = SecureRandom.hex if v.blank? }
end
class << self
def pw_for(domain_name)
name_in_unicode = SimpleIDN.to_ascii(domain_name)
by_domain(domain_name).select("names -> '#{domain_name}' AS pw").first.try(:pw) ||
by_domain(name_in_unicode).select("names -> '#{name_in_unicode}' AS pw").first.try(:pw)
name_in_ascii = SimpleIDN.to_ascii(domain_name)
by_domain(domain_name).first.try(:password) || by_domain(name_in_ascii).first.try(:password)
end
def by_domain name
where("names ? '#{name}'")
where(name: name)
end
def any_of_domains names
where("names ?| ARRAY['#{names.join("','")}']")
where(name: names)
end
end
def fill_empty_passwords
self.password = SecureRandom.hex unless self.password
end
def name= val
super SimpleIDN.to_unicode(val)
end
end