nopaque/app/admin/json_routes.py

24 lines
699 B
Python
Raw 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()
resonse_data = {
'message': (
f'User "{user.username}" is now '
f'{"confirmed" if confirmed else "unconfirmed"}'
)
}
return resonse_data, 200