Allow skipping initial user creation

This commit is contained in:
Alex Ling 2020-05-31 14:25:15 +00:00
parent 651bd17612
commit 8bbbe650f1

View File

@ -22,7 +22,7 @@ class Storage
@@default.not_nil! @@default.not_nil!
end end
def initialize(db_path : String? = nil) def initialize(db_path : String? = nil, init_user = true)
@path = db_path || Config.current.db_path @path = db_path || Config.current.db_path
dir = File.dirname @path dir = File.dirname @path
unless Dir.exists? dir unless Dir.exists? dir
@ -51,12 +51,15 @@ class Storage
Logger.debug "Creating DB file at #{@path}" Logger.debug "Creating DB file at #{@path}"
db.exec "create unique index username_idx on users (username)" db.exec "create unique index username_idx on users (username)"
db.exec "create unique index token_idx on users (token)" db.exec "create unique index token_idx on users (token)"
random_pw = random_str
hash = hash_password random_pw if init_user
db.exec "insert into users values (?, ?, ?, ?)", random_pw = random_str
"admin", hash, nil, 1 hash = hash_password random_pw
Logger.log "Initial user created. You can log in with " \ db.exec "insert into users values (?, ?, ?, ?)",
"#{{"username" => "admin", "password" => random_pw}}" "admin", hash, nil, 1
Logger.log "Initial user created. You can log in with " \
"#{{"username" => "admin", "password" => random_pw}}"
end
end end
end end
end end