mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
24 lines
699 B
Python
24 lines
699 B
Python
from flask import abort, request
|
|
from app import db
|
|
from app.decorators import content_negotiation
|
|
from app.models import User
|
|
from . import bp
|
|
|
|
|
|
@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
|