mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-19 19:38:51 +00:00
Move DB queries related to session tokens in a separate module
This commit is contained in:
@@ -312,7 +312,7 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
user = env.get("user").as(User)
|
||||
scopes = env.get("scopes").as(Array(String))
|
||||
|
||||
tokens = PG_DB.query_all("SELECT id, issued FROM session_ids WHERE email = $1", user.email, as: {session: String, issued: Time})
|
||||
tokens = Invidious::Database::SessionIDs.select_all(user.email)
|
||||
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
@@ -400,9 +400,9 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
|
||||
# Allow tokens to revoke other tokens with correct scope
|
||||
if session == env.get("session").as(String)
|
||||
PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", session)
|
||||
Invidious::Database::SessionIDs.delete(sid: session)
|
||||
elsif scopes_include_scope(scopes, "GET:tokens")
|
||||
PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", session)
|
||||
Invidious::Database::SessionIDs.delete(sid: session)
|
||||
else
|
||||
return error_json(400, "Cannot revoke session #{session}")
|
||||
end
|
||||
|
||||
@@ -336,7 +336,7 @@ module Invidious::Routes::Login
|
||||
|
||||
if Crypto::Bcrypt::Password.new(user.password.not_nil!).verify(password.byte_slice(0, 55))
|
||||
sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
||||
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)
|
||||
Invidious::Database::SessionIDs.insert(sid, email)
|
||||
|
||||
if Kemal.config.ssl || CONFIG.https_only
|
||||
secure = true
|
||||
@@ -455,7 +455,7 @@ module Invidious::Routes::Login
|
||||
args = arg_array(user_array)
|
||||
|
||||
PG_DB.exec("INSERT INTO users VALUES (#{args})", args: user_array)
|
||||
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)
|
||||
Invidious::Database::SessionIDs.insert(sid, email)
|
||||
|
||||
view_name = "subscriptions_#{sha256(user.email)}"
|
||||
PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS #{MATERIALIZED_VIEW_SQL.call(user.email)}")
|
||||
@@ -511,7 +511,7 @@ module Invidious::Routes::Login
|
||||
return error_template(400, ex)
|
||||
end
|
||||
|
||||
PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", sid)
|
||||
Invidious::Database::SessionIDs.delete(sid: sid)
|
||||
|
||||
env.request.cookies.each do |cookie|
|
||||
cookie.expires = Time.utc(1990, 1, 1)
|
||||
|
||||
Reference in New Issue
Block a user