Изменение токена по нику на токен по айди

This commit is contained in:
Your Name 2024-11-30 08:45:14 +03:00
parent 3d550af0f6
commit 2e15398259
3 changed files with 28 additions and 19 deletions

33
api.py
View File

@ -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

View File

@ -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') )

9
tg.py
View File

@ -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 == 'Баланс':