updated response to login API
This commit is contained in:
@@ -72,16 +72,36 @@ def validate_management_api_key(api_key):
|
||||
|
||||
@admin_api.route('/login', methods=['POST'])
|
||||
def admin_login():
|
||||
data = request.get_json()
|
||||
if not data or 'email' not in data or 'password' not in data:
|
||||
return jsonify({'message': 'Email and password are required'}), 400
|
||||
user = User.query.filter_by(email=data['email']).first()
|
||||
if not user or not user.is_admin or not user.check_password(data['password']):
|
||||
return jsonify({'message': 'Invalid credentials or not an admin'}), 401
|
||||
token = jwt.encode({
|
||||
'user_id': user.id
|
||||
}, current_app.config['SECRET_KEY'], algorithm="HS256")
|
||||
return jsonify({'token': token})
|
||||
try:
|
||||
data = request.get_json()
|
||||
if not data or 'email' not in data or 'password' not in data:
|
||||
return jsonify({
|
||||
'message': 'Email and password are required',
|
||||
'status': 'error'
|
||||
}), 400
|
||||
|
||||
user = User.query.filter_by(email=data['email']).first()
|
||||
if not user or not user.is_admin or not user.check_password(data['password']):
|
||||
return jsonify({
|
||||
'message': 'Invalid credentials or not an admin',
|
||||
'status': 'error'
|
||||
}), 401
|
||||
|
||||
token = jwt.encode({
|
||||
'user_id': user.id
|
||||
}, current_app.config['SECRET_KEY'], algorithm="HS256")
|
||||
|
||||
return jsonify({
|
||||
'token': token,
|
||||
'status': 'success'
|
||||
}), 200
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Login error: {str(e)}")
|
||||
return jsonify({
|
||||
'message': 'An error occurred during login',
|
||||
'status': 'error'
|
||||
}), 500
|
||||
|
||||
@admin_api.route('/management-token', methods=['POST'])
|
||||
def get_management_token():
|
||||
|
||||
Reference in New Issue
Block a user