updated authentication of instances
This commit is contained in:
@@ -482,6 +482,27 @@ def init_routes(main_bp):
|
||||
|
||||
return jsonify(status_info)
|
||||
|
||||
@main_bp.route('/instances/<int:instance_id>/save-token', methods=['POST'])
|
||||
@login_required
|
||||
@require_password_change
|
||||
def save_instance_token(instance_id):
|
||||
if not os.environ.get('MASTER', 'false').lower() == 'true':
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
instance = Instance.query.get_or_404(instance_id)
|
||||
data = request.get_json()
|
||||
|
||||
if not data or 'token' not in data:
|
||||
return jsonify({'error': 'Token is required'}), 400
|
||||
|
||||
try:
|
||||
instance.connection_token = data['token']
|
||||
db.session.commit()
|
||||
return jsonify({'message': 'Token saved successfully'})
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return jsonify({'error': str(e)}), 400
|
||||
|
||||
UPLOAD_FOLDER = '/app/uploads/profile_pics'
|
||||
if not os.path.exists(UPLOAD_FOLDER):
|
||||
os.makedirs(UPLOAD_FOLDER)
|
||||
|
||||
Reference in New Issue
Block a user