From 8490cad1911d66cdfaba161d7d5254ddc6cbbc55 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 15 Feb 2020 23:48:56 +0000 Subject: [PATCH] - return the existing token when login --- src/storage.cr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/storage.cr b/src/storage.cr index d9683b3..f366ccb 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -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