Compare commits
No commits in common. "63f17cfc7a9746003de0caebbe9678a7ecda906b" and "4c3dcfe0e5ce300da58b1087e0d7cc397ee95c4a" have entirely different histories.
63f17cfc7a
...
4c3dcfe0e5
|
@ -11,10 +11,6 @@ from amanuensis.db import DbContext, User
|
|||
from amanuensis.errors import ArgumentError
|
||||
|
||||
|
||||
RE_NO_LETTERS = re.compile(r'^[0-9-_]*$')
|
||||
RE_ALPHANUM_DASH_UNDER = re.compile(r'^[A-Za-z0-9-_]*$')
|
||||
|
||||
|
||||
def create_user(
|
||||
db: DbContext,
|
||||
username: str,
|
||||
|
@ -26,30 +22,19 @@ def create_user(
|
|||
Create a new user.
|
||||
"""
|
||||
# Verify username
|
||||
if not isinstance(username, str):
|
||||
raise ArgumentError('Username must be a string')
|
||||
if len(username) < 3 or len(username) > 32:
|
||||
raise ArgumentError('Username must be between 3 and 32 characters')
|
||||
if RE_NO_LETTERS.match(username):
|
||||
if re.match(r'^[0-9-_]*$', username):
|
||||
raise ArgumentError('Username must contain a letter')
|
||||
if not RE_ALPHANUM_DASH_UNDER.match(username):
|
||||
if not re.match(r'^[A-Za-z0-9-_]*$', username):
|
||||
raise ArgumentError('Username may only contain alphanumerics, dash, and underscore')
|
||||
|
||||
# Verify password
|
||||
if not isinstance(password, str):
|
||||
raise ArgumentError('Password must be a string')
|
||||
|
||||
# Verify display name
|
||||
if display_name is not None and not isinstance(display_name, str):
|
||||
raise ArgumentError('Display name must be a string')
|
||||
if not password:
|
||||
raise ArgumentError('Password must be provided')
|
||||
# If display name is not provided, use the username
|
||||
if not display_name or not display_name.strip():
|
||||
display_name = username
|
||||
|
||||
# Verify email
|
||||
if not isinstance(email, str):
|
||||
raise ArgumentError('Email must be a string')
|
||||
|
||||
# Query the db to make sure the username isn't taken
|
||||
if db.session.query(func.count(User.id)).filter(User.username == username).scalar() > 0:
|
||||
raise ArgumentError('Username is already taken')
|
||||
|
|
|
@ -148,7 +148,7 @@ class Lexicon(ModelBase):
|
|||
current_turn = Column(Integer, nullable=True)
|
||||
|
||||
# The number of turns in the game
|
||||
turn_count = Column(Integer, nullable=False, default=8)
|
||||
turn_count = Column(Integer, nullable=False)
|
||||
|
||||
################################
|
||||
# Visibility and join settings #
|
||||
|
|
Loading…
Reference in New Issue