mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Ensure generated numbers are always numbers
This commit is contained in:
parent
12e32af524
commit
f838a6506c
5 changed files with 14 additions and 2 deletions
|
@ -10,6 +10,7 @@ class LegalDocument < ActiveRecord::Base
|
|||
def save_to_filesystem
|
||||
loop do
|
||||
rand = SecureRandom.random_number.to_s.last(4)
|
||||
next if rand.to_i == 0 || rand.length < 4
|
||||
self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
||||
break unless File.file?(path)
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ class Registrar < ActiveRecord::Base
|
|||
base = nil
|
||||
loop do
|
||||
base = SecureRandom.random_number.to_s.last(8)
|
||||
break if base.length == 8
|
||||
break if base.to_i != 0 && base.length == 8
|
||||
end
|
||||
|
||||
control_base = (base + '2715' + '00').to_i
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue