Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,17 +33,15 @@ def register():
|
|
| 33 |
|
| 34 |
# Check if the username already exists
|
| 35 |
if User.query.filter_by(username=username).first():
|
| 36 |
-
return "Username already exists. Please choose another."
|
| 37 |
|
| 38 |
-
# Hash the password
|
| 39 |
hashed_password = generate_password_hash(password)
|
| 40 |
-
|
| 41 |
-
# Save the user to the database
|
| 42 |
new_user = User(username=username, password=hashed_password)
|
| 43 |
db.session.add(new_user)
|
| 44 |
db.session.commit()
|
| 45 |
|
| 46 |
-
return "User registered successfully!"
|
| 47 |
|
| 48 |
# User login route
|
| 49 |
@app.route('/login', methods=['POST'])
|
|
|
|
| 33 |
|
| 34 |
# Check if the username already exists
|
| 35 |
if User.query.filter_by(username=username).first():
|
| 36 |
+
return "Username already exists. Please choose another.", 400
|
| 37 |
|
| 38 |
+
# Hash the password and save the user to the database
|
| 39 |
hashed_password = generate_password_hash(password)
|
|
|
|
|
|
|
| 40 |
new_user = User(username=username, password=hashed_password)
|
| 41 |
db.session.add(new_user)
|
| 42 |
db.session.commit()
|
| 43 |
|
| 44 |
+
return "User registered successfully!", 201
|
| 45 |
|
| 46 |
# User login route
|
| 47 |
@app.route('/login', methods=['POST'])
|