diff --git a/api.py b/api.py index 73d0f89..993ae01 100644 --- a/api.py +++ b/api.py @@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException from pydantic import BaseModel from datetime import datetime, timedelta from statistics import median +from uuid import uuid4 # Fix 3.3 + 0.15 = 3.4499999999999997 from decimal import Decimal as d @@ -322,23 +323,6 @@ def update_passwd(it: Update_passwd): else: return 'Error' -# DEPRECATED -# class Update_time(BaseModel): - # token: str - # id: str - # time: str -# @app.post('/api/update_time/') -# def update_time(it: Update_time): - # token, id, time = it.token, it.id, int(it.time) - # if token_check(token): - # db = read() - # db['id'][id]['time'] = time - # write(db) - # return 'OK' - # else: - # return 'Error' - - class Add_time(BaseModel): token: str id: str @@ -478,7 +462,20 @@ def get_stat(it: Get_stat): else: return 'Error' -# TODO: unauth from account +class Token_gen(BaseModel): + token: str + id: str +@app.post('/api/token_gen/') +def token_gen(it: Token_gen): + token, id = it.token, it.id + if token_check(token): + user_token = str(uuid4()) + user_api = read('user_api.json') + user_api['tokens'][id] = user_token + write(user_api, 'user_api.json') + return user_token + else: + return 'Error' if __name__ == '__main__': import uvicorn diff --git a/call2api.py b/call2api.py index 531cfbd..d571696 100644 --- a/call2api.py +++ b/call2api.py @@ -132,7 +132,10 @@ def get_stat(token): def transfer_callback(addr, token, src_nick, dst_nick, amount): amount = str(amount) data = {'token': token, 'src_nick': src_nick, 'dst_nick': dst_nick, 'amount': amount} - print(addr + 'api/transfer_callback/') return call(addr + 'api/transfer_callback/', data, pre=False) +def token_gen(token, id): + data = {'token': token, 'id': id} + return call('api/token_gen/', data) + #print( user_in_db('ee77b9d8-44f3-4e01-a702-69d5524ee50b', '1234') ) diff --git a/tg.py b/tg.py index 838ea6b..d294da0 100644 --- a/tg.py +++ b/tg.py @@ -236,6 +236,15 @@ def set_course(message): CDM в час: `{conf['time2cdm']*3600}`''', parse_mode = 'Markdown') +@bot.message_handler(commands=['token_gen']) +def token_gen_tg(message): + if checkauth(message): + id = user_in_db(API_TOKEN, tg=message.chat.id) + token = token_gen(API_TOKEN, id) + bot.reply_to(message, f'''Ваш новый токен: {hcode(f"{token}")} + +⚠️ВНИМАНИЕ, не передавайте никому токен. Администрация не спрашивает токены.⚠️''', parse_mode='HTML') + @bot.message_handler(func=lambda message: True) def checks(message): if message.text == 'Баланс':