Add commands for API token retrieval/refreshing

This commit is contained in:
Ske 2018-11-13 12:34:19 +01:00
parent a72a7c3de9
commit 6da7436aed
4 changed files with 60 additions and 7 deletions

View file

@ -1,7 +1,7 @@
from collections import namedtuple
from datetime import datetime
import logging
from typing import List
from typing import List, Optional
import time
import asyncpg
@ -85,6 +85,11 @@ async def get_system_by_account(conn, account_id: int) -> System:
row = await conn.fetchrow("select systems.* from systems, accounts where accounts.uid = $1 and accounts.system = systems.id", account_id)
return System(**row) if row else None
@db_wrap
async def get_system_by_token(conn, token: str) -> Optional[System]:
row = await conn.fetchrow("select * from systems where token = $1", token)
return System(**row) if row else None
@db_wrap
async def get_system_by_hid(conn, system_hid: str) -> System:
row = await conn.fetchrow("select * from systems where hid = $1", system_hid)
@ -323,6 +328,7 @@ async def create_tables(conn):
description text,
tag text,
avatar_url text,
token text,
created timestamp not null default (current_timestamp at time zone 'utc')
)""")
await conn.execute("""create table if not exists members (