mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +02:00
Story#108091488 - Seems that now reserved domains will be in better table
This commit is contained in:
parent
3c33a44f38
commit
6415bfae38
4 changed files with 34 additions and 16 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue