mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-14 14:22:16 +00:00
Add email column
This commit is contained in:
parent
3d9b387ea8
commit
c299450d1c
5 changed files with 36 additions and 8 deletions
|
@ -7,7 +7,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|||
|
||||
from server.extensions import db
|
||||
from server.models import Users, Sessions
|
||||
from server.config import USER_REGEX
|
||||
from server.config import USER_REGEX, USER_EMAIL_REGEX
|
||||
|
||||
|
||||
blueprint = Blueprint("auth", __name__)
|
||||
|
@ -22,16 +22,18 @@ def auth():
|
|||
def register():
|
||||
# Get the form data
|
||||
username = request.form["username"].strip()
|
||||
email = request.form["email"].strip()
|
||||
password = request.form["password"].strip()
|
||||
username_regex = re.compile(USER_REGEX)
|
||||
|
||||
username_regex = re.compile(USER_REGEX)
|
||||
email_regex = re.compile(USER_EMAIL_REGEX)
|
||||
error = []
|
||||
|
||||
# Validate the form
|
||||
if not username or not username_regex.match(username):
|
||||
error.append(
|
||||
"Username is empty or invalid! Must be alphanumeric, and can contain ._-"
|
||||
)
|
||||
error.append("Username is invalid! Must be alphanumeric, and can contain ._-")
|
||||
if not email or not email_regex.match(email):
|
||||
error.append("Email is invalid! Must be email format")
|
||||
if not password:
|
||||
error.append("Password is empty!")
|
||||
elif len(password) < 8:
|
||||
|
@ -48,6 +50,7 @@ def register():
|
|||
register_user = Users(
|
||||
alt_id=str(uuid.uuid4()),
|
||||
username=username,
|
||||
email=generate_password_hash(email, method="scrypt"),
|
||||
password=generate_password_hash(password, method="scrypt"),
|
||||
)
|
||||
db.session.add(register_user)
|
||||
|
|
|
@ -7,6 +7,7 @@ GAME_DIFFICULTIES = [0, 1, 2, 3, 4]
|
|||
|
||||
USER_MAX_TOKENS = 3
|
||||
USER_REGEX = r"\b[A-Za-z0-9._-]+\b"
|
||||
USER_EMAIL_REGEX = r"[^@]+@[^@]+\.[^@]+"
|
||||
|
||||
MAX_TOP_SCORES = 15
|
||||
MAX_SEARCH_RESULTS = 5
|
||||
|
|
|
@ -56,6 +56,23 @@ class Sessions(db.Model):
|
|||
)
|
||||
|
||||
|
||||
class Reset(db.Model):
|
||||
"""
|
||||
Password reset table
|
||||
"""
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
user_id = db.Column(db.Integer, db.ForeignKey("users.id", use_alter=True))
|
||||
reset_key = db.Column(db.String, nullable=False, unique=True)
|
||||
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
nullable=False,
|
||||
server_default=db.func.now(),
|
||||
)
|
||||
|
||||
|
||||
class Users(db.Model, UserMixin):
|
||||
"""
|
||||
User table
|
||||
|
@ -65,7 +82,9 @@ class Users(db.Model, UserMixin):
|
|||
alt_id = db.Column(db.String, nullable=False, unique=True)
|
||||
|
||||
username = db.Column(db.String(32), unique=True, nullable=False)
|
||||
email = db.Column(db.String, unique=True, nullable=False)
|
||||
password = db.Column(db.String, nullable=False)
|
||||
|
||||
joined_at = db.Column(
|
||||
db.DateTime,
|
||||
nullable=False,
|
||||
|
|
|
@ -20,13 +20,18 @@
|
|||
|
||||
<div class="block">
|
||||
<h2>Register</h2>
|
||||
<p>Don't have an account? Register here!</p>
|
||||
<p>Don't have an account?</p>
|
||||
<form action="{{ url_for('auth.register') }}" method="POST">
|
||||
<span class="text-input">
|
||||
<label for="register-username">Username</label>
|
||||
<input type="text" name="username" placeholder="Jerry" id="register-username" required>
|
||||
</span>
|
||||
|
||||
<span class="text-input">
|
||||
<label for="register-email">Username</label>
|
||||
<input type="text" name="email" placeholder="jerry@example.com" id="register-email" required>
|
||||
</span>
|
||||
|
||||
<span class="text-input">
|
||||
<label for="register-password">Password</label>
|
||||
<input type="password" name="password" placeholder="password123" id="register-password" required>
|
||||
|
|
|
@ -21,8 +21,8 @@ services:
|
|||
db:
|
||||
image: postgres:alpine
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5432:5432"
|
||||
# ports:
|
||||
# - "5432:5432"
|
||||
volumes:
|
||||
- ./Postgres/data:/var/lib/postgresql/data
|
||||
environment:
|
||||
|
|
Loading…
Add table
Reference in a new issue