Compare commits

...

4 Commits

Author SHA1 Message Date
Alex Ling d2f95e5970 Bump version to v0.5.1 2020-06-03 08:22:05 +00:00
Alex Ling 82bcd03f15 Always create initial user if the DB is empty when started 2020-06-03 08:20:40 +00:00
Alex Ling fe799f30c8 Make the user listing command handles empty DB 2020-06-03 08:19:40 +00:00
Alex Ling 54123917af Empty ARGV before starting Kemal (#53) 2020-06-03 07:55:18 +00:00
4 changed files with 21 additions and 12 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ The official docker images are available on [Dockerhub](https://hub.docker.com/r
### CLI ### CLI
``` ```
Mango - Manga Server and Web Reader. Version 0.5.0 Mango - Manga Server and Web Reader. Version 0.5.1
Usage: Usage:
+1 -1
View File
@@ -1,5 +1,5 @@
name: mango name: mango
version: 0.5.0 version: 0.5.1
authors: authors:
- Alex Ling <hkalexling@gmail.com> - Alex Ling <hkalexling@gmail.com>
+4 -2
View File
@@ -4,7 +4,7 @@ require "./mangadex/*"
require "option_parser" require "option_parser"
require "clim" require "clim"
MANGO_VERSION = "0.5.0" MANGO_VERSION = "0.5.1"
macro common_option macro common_option
option "-c PATH", "--config=PATH", type: String, option "-c PATH", "--config=PATH", type: String,
@@ -29,6 +29,8 @@ class CLI < Clim
Config.load(opts.config).set_current Config.load(opts.config).set_current
MangaDex::Downloader.default MangaDex::Downloader.default
# empty ARGV so it won't be passed to Kemal
ARGV.clear
server = Server.new server = Server.new
server.start server.start
end end
@@ -75,7 +77,7 @@ class CLI < Clim
password.not_nil!, opts.admin password.not_nil!, opts.admin
when "list" when "list"
users = storage.list_users users = storage.list_users
name_length = users.map(&.[0].size).max name_length = users.map(&.[0].size).max? || 0
l_cell_width = ["username".size, name_length].max l_cell_width = ["username".size, name_length].max
r_cell_width = "admin access".size r_cell_width = "admin access".size
header = " #{"username".ljust l_cell_width} | admin access " header = " #{"username".ljust l_cell_width} | admin access "
+11 -4
View File
@@ -47,12 +47,22 @@ class Storage
Logger.fatal "Error when checking tables in DB: #{e}" Logger.fatal "Error when checking tables in DB: #{e}"
raise e raise e
end end
# If the DB is initialized through CLI but no user is added, we need
# to create the admin user when first starting the app
user_count = db.query_one "select count(*) from users", as: Int32
init_admin if init_user && user_count == 0
else else
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)"
if init_user init_admin if init_user
end
end
end
macro init_admin
random_pw = random_str random_pw = random_str
hash = hash_password random_pw hash = hash_password random_pw
db.exec "insert into users values (?, ?, ?, ?)", db.exec "insert into users values (?, ?, ?, ?)",
@@ -60,9 +70,6 @@ class Storage
Logger.log "Initial user created. You can log in with " \ Logger.log "Initial user created. You can log in with " \
"#{{"username" => "admin", "password" => random_pw}}" "#{{"username" => "admin", "password" => random_pw}}"
end end
end
end
end
def verify_user(username, password) def verify_user(username, password)
DB.open "sqlite3://#{@path}" do |db| DB.open "sqlite3://#{@path}" do |db|