fix: resolve AttributeError in User model and ensure consistent password handling
- Fixed the `AttributeError: 'User' object has no attribute '_password'` by properly mapping the `_password` attribute to the `password` column in the database. - Updated the `User` model to ensure passwords are only hashed once during creation and not re-hashed when retrieved or updated. - Improved the `check_password` method to correctly compare hashed passwords. - Verified the signup and login flow to ensure consistent behavior
This commit is contained in:
		
							parent
							
								
									d13c5885d8
								
							
						
					
					
						commit
						4a4d693d72
					
				
					 4 changed files with 36 additions and 19 deletions
				
			
		|  | @ -1,5 +1,5 @@ | |||
| # routes/auth.py | ||||
| from flask import Blueprint, request, jsonify | ||||
| from flask import Blueprint, request, jsonify, session | ||||
| from services.UserService.user import UserService | ||||
| 
 | ||||
| auth_bp = Blueprint('auth', __name__) | ||||
|  | @ -17,8 +17,20 @@ def signup(): | |||
| @auth_bp.route('/login', methods=['POST']) | ||||
| def login(): | ||||
|     data = request.get_json() | ||||
|     username = data.get('username') | ||||
|     password = data.get('password') | ||||
|      | ||||
|     print(f"Login attempt: username={username}, password={password}") | ||||
|       | ||||
|     try: | ||||
|         user = user_service.verify_user(data['username'], data['password']) | ||||
|         session['user_id'] = user.id | ||||
|         return jsonify({"message": "Login successful", "user_id": user.id}), 200 | ||||
|     except ValueError as e: | ||||
|         print(f"Login failed: {str(e)}") | ||||
|         return jsonify({"error": str(e)}), 401 | ||||
|      | ||||
| @auth_bp.route('/logout', methods=['POST']) | ||||
| def logout(): | ||||
|     session.clear() | ||||
|     return jsonify({"message": "Logout successful"}), 200 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Blake Ridgway
						Blake Ridgway