diff --git a/litecord/auth.py b/litecord/auth.py
index 0341fb9..849a45a 100644
--- a/litecord/auth.py
+++ b/litecord/auth.py
@@ -19,8 +19,6 @@ along with this program. If not, see .
import base64
import binascii
-from random import randint
-from typing import Tuple
import bcrypt
from itsdangerous import TimestampSigner, BadSignature
@@ -28,7 +26,6 @@ from logbook import Logger
from quart import request, current_app as app
from litecord.errors import Forbidden, Unauthorized
-from litecord.snowflake import get_snowflake
from litecord.enums import UserFlags
diff --git a/litecord/blueprints/users.py b/litecord/blueprints/users.py
index cf49d9f..9223c61 100644
--- a/litecord/blueprints/users.py
+++ b/litecord/blueprints/users.py
@@ -17,7 +17,6 @@ along with this program. If not, see .
"""
-from os import urandom
from asyncpg import UniqueViolationError
from quart import Blueprint, jsonify, request, current_app as app
@@ -41,6 +40,7 @@ from litecord.common.users import (
delete_user,
check_username_usage,
roll_discrim,
+ user_disconnect,
)
bp = Blueprint("user", __name__)
@@ -438,11 +438,6 @@ async def _get_mentions():
return jsonify(res)
-def rand_hex(length: int = 8) -> str:
- """Generate random hex characters."""
- return urandom(length).hex()[:length]
-
-
@bp.route("/@me/delete", methods=["POST"])
async def delete_account():
"""Delete own account.
diff --git a/litecord/common/users.py b/litecord/common/users.py
index bd67dd8..2b36082 100644
--- a/litecord/common/users.py
+++ b/litecord/common/users.py
@@ -1,3 +1,23 @@
+"""
+
+Litecord
+Copyright (C) 2018-2019 Luna Mendes
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+
+"""
+
+import logging
from random import randint
from typing import Tuple, Optional
@@ -7,6 +27,9 @@ from asyncpg import UniqueViolationError
from ..snowflake import get_snowflake
from ..errors import BadRequest
from ..auth import hash_data
+from ..utils import rand_hex
+
+log = logging.getLogger(__name__)
async def mass_user_update(user_id):
diff --git a/litecord/utils.py b/litecord/utils.py
index 15b89d2..91e7d8a 100644
--- a/litecord/utils.py
+++ b/litecord/utils.py
@@ -19,6 +19,7 @@ along with this program. If not, see .
import asyncio
import json
+import secrets
from typing import Any, Iterable, Optional, Sequence, List, Dict, Union
from logbook import Logger
@@ -284,3 +285,8 @@ def query_tuple_from_args(args: dict, limit: int) -> tuple:
before = int(args["after"])
return before, after
+
+
+def rand_hex(length: int = 8) -> str:
+ """Generate random hex characters."""
+ return secrets.token_hex(length)[:length]
diff --git a/tests/conftest.py b/tests/conftest.py
index 2a48d5c..f0444c9 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -30,10 +30,9 @@ from tests.common import email, TestClient
from run import app as main_app, set_blueprints
-from litecord.auth import create_user
+from litecord.common.users import create_user, delete_user
from litecord.enums import UserFlags
from litecord.blueprints.auth import make_token
-from litecord.blueprints.users import delete_user
@pytest.fixture(name="app")