nopaque/app/admin/json_routes.py

24 lines
701 B
Python
Raw Permalink Normal View History

2023-03-29 12:32:35 +00:00
from flask import abort, request
2023-03-14 13:24:52 +00:00
from app import db
2023-03-29 12:32:35 +00:00
from app.decorators import content_negotiation
2023-03-14 13:24:52 +00:00
from app.models import User
from . import bp
2023-03-29 12:32:35 +00:00
@bp.route('/users/<hashid:user_id>/confirmed', methods=['PUT'])
@content_negotiation(consumes='application/json', produces='application/json')
def update_user_role(user_id):
confirmed = request.json
if not isinstance(confirmed, bool):
abort(400)
user = User.query.get_or_404(user_id)
user.confirmed = confirmed
db.session.commit()
2023-04-11 11:30:38 +00:00
response_data = {
2023-03-29 12:32:35 +00:00
'message': (
f'User "{user.username}" is now '
f'{"confirmed" if confirmed else "unconfirmed"}'
)
}
2023-04-11 11:30:38 +00:00
return response_data, 200