- return the existing token when login

This commit is contained in:
Alex Ling 2020-02-15 23:48:56 +00:00
parent 7cf401e645
commit 8490cad191

View File

@ -48,11 +48,13 @@ class Storage
def verify_user(username, password)
DB.open "sqlite3://#{@path}" do |db|
begin
hash = db.query_one "select password from users where " \
"username = (?)", username, as: String
hash, token = db.query_one "select password, token from "\
"users where username = (?)", \
username, as: {String, String?}
unless verify_password hash, password
return nil
end
return token if token
token = random_str
db.exec "update users set token = (?) where username = (?)",
token, username