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

View File

@@ -50,7 +50,7 @@ The official docker images are available on [Dockerhub](https://hub.docker.com/r
### CLI
```
Mango - Manga Server and Web Reader. Version 0.5.0
Mango - Manga Server and Web Reader. Version 0.5.1
Usage:

View File

@@ -1,5 +1,5 @@
name: mango
version: 0.5.0
version: 0.5.1
authors:
- Alex Ling <hkalexling@gmail.com>

View File

@@ -4,7 +4,7 @@ require "./mangadex/*"
require "option_parser"
require "clim"
MANGO_VERSION = "0.5.0"
MANGO_VERSION = "0.5.1"
macro common_option
option "-c PATH", "--config=PATH", type: String,
@@ -29,6 +29,8 @@ class CLI < Clim
Config.load(opts.config).set_current
MangaDex::Downloader.default
# empty ARGV so it won't be passed to Kemal
ARGV.clear
server = Server.new
server.start
end
@@ -75,7 +77,7 @@ class CLI < Clim
password.not_nil!, opts.admin
when "list"
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
r_cell_width = "admin access".size
header = " #{"username".ljust l_cell_width} | admin access "

View File

@@ -47,23 +47,30 @@ class Storage
Logger.fatal "Error when checking tables in DB: #{e}"
raise e
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
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)"
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
init_admin if init_user
end
end
end
macro init_admin
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
def verify_user(username, password)
DB.open "sqlite3://#{@path}" do |db|
begin