Spaces:
Sleeping
Sleeping
Update signup.py
Browse files
signup.py
CHANGED
|
@@ -22,16 +22,19 @@ def signup_route():
|
|
| 22 |
|
| 23 |
|
| 24 |
if not username or not email or not password or not confirm_password or not role:
|
|
|
|
| 25 |
logging.warning('Empty field in signup attempt: %s', {'username': username, 'email': email})
|
| 26 |
return jsonify({'message': 'Please fill out all fields', 'status': 'danger'}), 400
|
| 27 |
|
| 28 |
|
| 29 |
if not re.match(r'^[^@]+@[^@]+\.[^@]+$', email):
|
|
|
|
| 30 |
logging.warning('Invalid email format: %s', email)
|
| 31 |
return jsonify({'message': 'Invalid email address! Please ensure it contains "@" and ".".', 'status': 'danger'}), 400
|
| 32 |
|
| 33 |
|
| 34 |
if password != confirm_password:
|
|
|
|
| 35 |
logging.warning('Password mismatch for user: %s', username)
|
| 36 |
return jsonify({'message': 'Passwords do not match', 'status': 'danger'}), 400
|
| 37 |
|
|
@@ -43,11 +46,13 @@ def signup_route():
|
|
| 43 |
preference_4 = request.form.get('preference_4')
|
| 44 |
|
| 45 |
if not all([preference_1, preference_2, preference_3, preference_4]):
|
|
|
|
| 46 |
logging.warning('Missing preferences for player role: %s', email)
|
| 47 |
return jsonify({'message': 'Please provide all four preferences', 'status': 'danger'}), 400
|
| 48 |
|
| 49 |
user = get_user_by_email(email)
|
| 50 |
if user:
|
|
|
|
| 51 |
logging.warning('Email already exists: %s', email)
|
| 52 |
return jsonify({'message': 'Email already exists', 'status': 'danger'}), 400
|
| 53 |
|
|
@@ -56,12 +61,15 @@ def signup_route():
|
|
| 56 |
|
| 57 |
add_user(username, email, password, role, preference_1, preference_2, preference_3, preference_4)
|
| 58 |
|
|
|
|
| 59 |
logging.info('User created successfully: %s', email)
|
| 60 |
return jsonify({'message': 'Account created successfully', 'status': 'success'}), 201
|
| 61 |
except Exception as db_error:
|
|
|
|
| 62 |
logging.error('Error adding user to database: %s', traceback.format_exc())
|
| 63 |
return jsonify({'message': 'Internal server error while adding user.', 'status': 'danger'}), 500
|
| 64 |
|
| 65 |
|
|
|
|
| 66 |
logging.error('Method not allowed: %s', request.method)
|
| 67 |
return jsonify({'message': 'Method not allowed', 'status': 'danger'}), 405
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
if not username or not email or not password or not confirm_password or not role:
|
| 25 |
+
print('Empty field in signup attempt: %s', {'username': username, 'email': email})
|
| 26 |
logging.warning('Empty field in signup attempt: %s', {'username': username, 'email': email})
|
| 27 |
return jsonify({'message': 'Please fill out all fields', 'status': 'danger'}), 400
|
| 28 |
|
| 29 |
|
| 30 |
if not re.match(r'^[^@]+@[^@]+\.[^@]+$', email):
|
| 31 |
+
print('Invalid email format: %s', email)
|
| 32 |
logging.warning('Invalid email format: %s', email)
|
| 33 |
return jsonify({'message': 'Invalid email address! Please ensure it contains "@" and ".".', 'status': 'danger'}), 400
|
| 34 |
|
| 35 |
|
| 36 |
if password != confirm_password:
|
| 37 |
+
print('Password mismatch for user: %s', username)
|
| 38 |
logging.warning('Password mismatch for user: %s', username)
|
| 39 |
return jsonify({'message': 'Passwords do not match', 'status': 'danger'}), 400
|
| 40 |
|
|
|
|
| 46 |
preference_4 = request.form.get('preference_4')
|
| 47 |
|
| 48 |
if not all([preference_1, preference_2, preference_3, preference_4]):
|
| 49 |
+
print('Missing preferences for player role: %s', email)
|
| 50 |
logging.warning('Missing preferences for player role: %s', email)
|
| 51 |
return jsonify({'message': 'Please provide all four preferences', 'status': 'danger'}), 400
|
| 52 |
|
| 53 |
user = get_user_by_email(email)
|
| 54 |
if user:
|
| 55 |
+
print('Email already exists: %s', email)
|
| 56 |
logging.warning('Email already exists: %s', email)
|
| 57 |
return jsonify({'message': 'Email already exists', 'status': 'danger'}), 400
|
| 58 |
|
|
|
|
| 61 |
|
| 62 |
add_user(username, email, password, role, preference_1, preference_2, preference_3, preference_4)
|
| 63 |
|
| 64 |
+
print('User created successfully: %s', email)
|
| 65 |
logging.info('User created successfully: %s', email)
|
| 66 |
return jsonify({'message': 'Account created successfully', 'status': 'success'}), 201
|
| 67 |
except Exception as db_error:
|
| 68 |
+
print('Error adding user to database: %s', traceback.format_exc())
|
| 69 |
logging.error('Error adding user to database: %s', traceback.format_exc())
|
| 70 |
return jsonify({'message': 'Internal server error while adding user.', 'status': 'danger'}), 500
|
| 71 |
|
| 72 |
|
| 73 |
+
print('Method not allowed: %s', request.method)
|
| 74 |
logging.error('Method not allowed: %s', request.method)
|
| 75 |
return jsonify({'message': 'Method not allowed', 'status': 'danger'}), 405
|