mirror of
https://github.com/openmax-server/server.git
synced 2026-05-22 19:41:41 +03:00
Генерируем айди пользователей рандомно (опять, да)
This commit is contained in:
@@ -6,9 +6,9 @@ class SQLQueries:
|
|||||||
|
|
||||||
INSERT_USER = """
|
INSERT_USER = """
|
||||||
INSERT INTO users
|
INSERT INTO users
|
||||||
(phone, telegram_id, firstname, lastname, username,
|
(id, phone, telegram_id, firstname, lastname, username,
|
||||||
profileoptions, options, accountstatus, updatetime, lastseen)
|
profileoptions, options, accountstatus, updatetime, lastseen)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
INSERT_USER_DATA = """
|
INSERT_USER_DATA = """
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
import secrets
|
||||||
import time
|
import time
|
||||||
import os
|
|
||||||
|
|
||||||
import geoip2.database
|
import geoip2.database
|
||||||
|
|
||||||
@@ -562,4 +562,14 @@ class Tools:
|
|||||||
response = reader.country(ip)
|
response = reader.country(ip)
|
||||||
return response.country.name or "Localhost Federation"
|
return response.country.name or "Localhost Federation"
|
||||||
except Exception:
|
except Exception:
|
||||||
return "Localhost Federation"
|
return "Localhost Federation"
|
||||||
|
|
||||||
|
async def generate_user_id(self, db_pool):
|
||||||
|
"""Генерация id пользователя"""
|
||||||
|
async with db_pool.acquire() as conn:
|
||||||
|
async with conn.cursor() as cursor:
|
||||||
|
while True:
|
||||||
|
user_id = secrets.randbelow(2_147_383_647) + 100_000
|
||||||
|
await cursor.execute("SELECT id FROM users WHERE id = %s", (user_id,))
|
||||||
|
if not await cursor.fetchone():
|
||||||
|
return user_id
|
||||||
|
|||||||
@@ -397,15 +397,19 @@ class AuthProcessors(BaseProcessor):
|
|||||||
now_ms = int(time.time() * 1000)
|
now_ms = int(time.time() * 1000)
|
||||||
now_s = int(time.time())
|
now_s = int(time.time())
|
||||||
|
|
||||||
|
# Генерируем ID пользователя
|
||||||
|
user_id = await self.tools.generate_user_id(self.db_pool)
|
||||||
|
|
||||||
# Создаем пользователя
|
# Создаем пользователя
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO users
|
INSERT INTO users
|
||||||
(phone, telegram_id, firstname, lastname, username,
|
(id, phone, telegram_id, firstname, lastname, username,
|
||||||
profileoptions, options, accountstatus, updatetime, lastseen)
|
profileoptions, options, accountstatus, updatetime, lastseen)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
user_id,
|
||||||
phone,
|
phone,
|
||||||
None,
|
None,
|
||||||
first_name,
|
first_name,
|
||||||
@@ -419,8 +423,6 @@ class AuthProcessors(BaseProcessor):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
user_id = cursor.lastrowid
|
|
||||||
|
|
||||||
# Добавляем данные аккаунта
|
# Добавляем данные аккаунта
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -88,10 +88,14 @@ class TelegramBot:
|
|||||||
username = (message.from_user.username or f"user{int(time.time() * 1000)}")[:60]
|
username = (message.from_user.username or f"user{int(time.time() * 1000)}")[:60]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Генерируем ID пользователя
|
||||||
|
user_id = await self.tools.generate_user_id(self.db_pool)
|
||||||
|
|
||||||
# Создаем юзера
|
# Создаем юзера
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
self.sql_queries.INSERT_USER,
|
self.sql_queries.INSERT_USER,
|
||||||
(
|
(
|
||||||
|
user_id, # id
|
||||||
new_phone, # phone
|
new_phone, # phone
|
||||||
tg_id, # telegram_id
|
tg_id, # telegram_id
|
||||||
firstname, # firstname
|
firstname, # firstname
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
CREATE TABLE `users` (
|
CREATE TABLE `users` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` INT NOT NULL,
|
||||||
`phone` VARCHAR(20) UNIQUE,
|
`phone` VARCHAR(20) UNIQUE,
|
||||||
`telegram_id` VARCHAR(64) UNIQUE,
|
`telegram_id` VARCHAR(64) UNIQUE,
|
||||||
`firstname` VARCHAR(59) NOT NULL,
|
`firstname` VARCHAR(59) NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user