Spaces:
Sleeping
Sleeping
| from flask import Blueprint, request, jsonify | |
| from api.services.auth_service import AuthService | |
| from flask_jwt_extended import jwt_required, get_jwt_identity | |
| from api.models.user import User | |
| auth_bp = Blueprint('auth', __name__, url_prefix='/api/auth') | |
| def login(): | |
| data = request.get_json() | |
| email = data.get('email') | |
| password = data.get('password') | |
| if not email or not password: | |
| return jsonify({'status': False, 'message': 'Missing email or password'}), 400 | |
| result = AuthService.login(email, password) | |
| if result['status']: | |
| return jsonify(result), 200 | |
| return jsonify(result), 401 | |
| def register(): | |
| data = request.get_json() | |
| email = data.get('email') | |
| password = data.get('password') | |
| name = data.get('name') | |
| if not email or not password or not name: | |
| return jsonify({'status': False, 'message': 'Missing required fields'}), 400 | |
| result = AuthService.register(email, password, name) | |
| if result['status']: | |
| return jsonify(result), 201 | |
| return jsonify(result), 400 | |
| def get_me(): | |
| user_id = get_jwt_identity() | |
| user = User.query.get(user_id) | |
| if user: | |
| return jsonify(user.to_dict()), 200 | |
| return jsonify({'status': False, 'message': 'User not found'}), 404 |