mirror of https://gitlab.com/litecord/litecord.git
remove some app and db params/kwargs from auth functions
This commit is contained in:
parent
b0ef3c4d0c
commit
a3f793a211
|
|
@ -152,10 +152,9 @@ async def hash_data(data: str, loop=None) -> str:
|
|||
return hashed.decode()
|
||||
|
||||
|
||||
async def check_username_usage(username: str, db=None):
|
||||
async def check_username_usage(username: str):
|
||||
"""Raise an error if too many people are with the same username."""
|
||||
db = db or app.db
|
||||
same_username = await db.fetchval(
|
||||
same_username = await app.db.fetchval(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM users
|
||||
|
|
@ -175,23 +174,21 @@ async def check_username_usage(username: str, db=None):
|
|||
|
||||
|
||||
def _raw_discrim() -> str:
|
||||
new_discrim = randint(1, 9999)
|
||||
new_discrim = "%04d" % new_discrim
|
||||
return new_discrim
|
||||
discrim_number = randint(1, 9999)
|
||||
return "%04d" % discrim_number
|
||||
|
||||
|
||||
async def roll_discrim(username: str, *, db=None) -> Optional[str]:
|
||||
async def roll_discrim(username: str) -> Optional[str]:
|
||||
"""Roll a discriminator for a DiscordTag.
|
||||
|
||||
Tries to generate one 10 times.
|
||||
|
||||
Calls check_username_usage.
|
||||
"""
|
||||
db = db or app.db
|
||||
|
||||
# we shouldn't roll discrims for usernames
|
||||
# that have been used too much.
|
||||
await check_username_usage(username, db)
|
||||
await check_username_usage(username)
|
||||
|
||||
# max 10 times for a reroll
|
||||
for _ in range(10):
|
||||
|
|
@ -199,7 +196,7 @@ async def roll_discrim(username: str, *, db=None) -> Optional[str]:
|
|||
discrim = _raw_discrim()
|
||||
|
||||
# check if anyone is with it
|
||||
res = await db.fetchval(
|
||||
res = await app.db.fetchval(
|
||||
"""
|
||||
SELECT id
|
||||
FROM users
|
||||
|
|
@ -217,19 +214,17 @@ async def roll_discrim(username: str, *, db=None) -> Optional[str]:
|
|||
return None
|
||||
|
||||
|
||||
async def create_user(
|
||||
username: str, email: str, password: str, db=None, loop=None
|
||||
) -> Tuple[int, str]:
|
||||
async def create_user(username: str, email: str, password: str) -> Tuple[int, str]:
|
||||
"""Create a single user.
|
||||
|
||||
Generates a distriminator and other information. You can fetch the user
|
||||
data back with :meth:`Storage.get_user`.
|
||||
"""
|
||||
db = db or app.db
|
||||
loop = loop or app.loop
|
||||
db = app.db
|
||||
loop = app.loop
|
||||
|
||||
new_id = get_snowflake()
|
||||
new_discrim = await roll_discrim(username, db=db)
|
||||
new_discrim = await roll_discrim(username)
|
||||
|
||||
if new_discrim is None:
|
||||
raise BadRequest(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
"""
|
||||
|
||||
from litecord.blueprints.auth import create_user, make_token
|
||||
from litecord.auth import create_user
|
||||
from litecord.blueprints.auth import make_token
|
||||
from litecord.blueprints.users import delete_user
|
||||
from litecord.enums import UserFlags
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue