| 1 |
""" |
| 2 |
Copyright 2020-2024 by J. Christopher Wagner (jwag). All rights reserved. |
| 3 |
:license: MIT, see LICENSE for more details. |
| 4 |
|
| 5 |
""" |
| 6 |
|
| 7 |
from datetime import datetime, timezone |
| 8 |
|
| 9 |
from flask import Blueprint, abort, current_app, jsonify, session |
| 10 |
from flask_security import auth_required |
| 11 |
|
| 12 |
from app import SmsCaptureSender |
| 13 |
|
| 14 |
api = Blueprint("api", __name__) |
| 15 |
|
| 16 |
|
| 17 |
@api.route("/health", methods=["GET"]) |
| 18 |
@auth_required("session") |
| 19 |
def health(): |
| 20 |
return jsonify(secret="lush oranges", date=datetime.now(timezone.utc)) |
| 21 |
|
| 22 |
|
| 23 |
@api.route("/popmail", methods=["GET"]) |
| 24 |
def popmail(): |
| 25 |
# This gets and pops the most recently sent email |
| 26 |
# Please please do not do this in your real application! |
| 27 |
mailer = current_app.extensions["mail"] |
| 28 |
sent = mailer.pop() |
| 29 |
if sent: |
| 30 |
return jsonify(mail=sent) |
| 31 |
abort(400) |
| 32 |
|
| 33 |
|
| 34 |
@api.route("/popsms", methods=["GET"]) |
| 35 |
def popsms(): |
| 36 |
# This gets and pops the most recently sent SMS |
| 37 |
# Please please do not do this in your real application! |
| 38 |
msg = SmsCaptureSender.pop() |
| 39 |
if msg: |
| 40 |
return jsonify(sms=msg) |
| 41 |
abort(400) |
| 42 |
|
| 43 |
|
| 44 |
@api.route("/resetfresh", methods=["GET"]) |
| 45 |
def resetfresh(): |
| 46 |
# This resets the callers session freshness field - just for testing |
| 47 |
old_paa = ( |
| 48 |
session["fs_paa"] |
| 49 |
- current_app.config["SECURITY_FRESHNESS"].total_seconds() |
| 50 |
- 100 |
| 51 |
) |
| 52 |
session["fs_paa"] = old_paa |
| 53 |
session.pop("fs_gexp", None) |
| 54 |
return jsonify() |