2022-06-23 14:26:36 +02:00
|
|
|
from flask import jsonify, g, request
|
|
|
|
from sqlalchemy_utils.types.arrow import arrow
|
|
|
|
|
|
|
|
from app.api.base import api_bp, require_api_auth
|
|
|
|
from app.db import Session
|
|
|
|
|
|
|
|
|
|
|
|
@api_bp.route("/sudo", methods=["PATCH"])
|
|
|
|
@require_api_auth
|
|
|
|
def enter_sudo():
|
|
|
|
"""
|
|
|
|
Enter sudo mode
|
|
|
|
|
|
|
|
Input
|
|
|
|
- password: user password to validate request to enter sudo mode
|
|
|
|
"""
|
|
|
|
user = g.user
|
|
|
|
data = request.get_json() or {}
|
|
|
|
if "password" not in data:
|
2022-06-28 14:40:06 +02:00
|
|
|
return jsonify(error="Invalid password"), 403
|
2022-06-23 14:26:36 +02:00
|
|
|
if not user.check_password(data["password"]):
|
2022-06-28 14:40:06 +02:00
|
|
|
return jsonify(error="Invalid password"), 403
|
2022-06-23 14:26:36 +02:00
|
|
|
|
|
|
|
g.api_key.sudo_mode_at = arrow.now()
|
|
|
|
Session.commit()
|
|
|
|
|
|
|
|
return jsonify(ok=True)
|