From 8bbbe650f1ed334789445c5458183fa804b52950 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sun, 31 May 2020 14:25:15 +0000 Subject: [PATCH] Allow skipping initial user creation --- src/storage.cr | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/storage.cr b/src/storage.cr index e6c0ad9..82341a8 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -22,7 +22,7 @@ class Storage @@default.not_nil! end - def initialize(db_path : String? = nil) + def initialize(db_path : String? = nil, init_user = true) @path = db_path || Config.current.db_path dir = File.dirname @path unless Dir.exists? dir @@ -51,12 +51,15 @@ class Storage Logger.debug "Creating DB file at #{@path}" db.exec "create unique index username_idx on users (username)" db.exec "create unique index token_idx on users (token)" - random_pw = random_str - hash = hash_password random_pw - db.exec "insert into users values (?, ?, ?, ?)", - "admin", hash, nil, 1 - Logger.log "Initial user created. You can log in with " \ - "#{{"username" => "admin", "password" => random_pw}}" + + if init_user + random_pw = random_str + hash = hash_password random_pw + db.exec "insert into users values (?, ?, ?, ?)", + "admin", hash, nil, 1 + Logger.log "Initial user created. You can log in with " \ + "#{{"username" => "admin", "password" => random_pw}}" + end end end end