-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
51 lines (42 loc) · 1.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import secrets
from typing import Any, List, Dict
from flask import Flask, Response, request, jsonify
app = Flask(__name__)
movies: List[Dict[str, Any]] = [
{"id": 1, "title": "The Godfather", "year": 1972, "genre": "Crime"},
{"id": 2, "title": "The Shawshank Redemption", "year": 1994, "genre": "Drama"},
{"id": 3, "title": "Schindler's List", "year": 1993, "genre": "Biography"},
{"id": 4, "title": "Raging Bull", "year": 1980, "genre": "Biography"},
{"id": 5, "title": "Casablanca", "year": 1942, "genre": "Romance"},
{"id": 6, "title": "Citizen Kane", "year": 1941, "genre": "Drama"},
]
@app.route("/auth", methods=["POST"])
def auth() -> Response:
"""
Perform authentication
"""
data: Any = request.get_json()
if (
{"username", "password"}.issubset(data)
and data["username"] == "admin"
and data["password"] == "admin"
):
access_token: str = secrets.token_urlsafe()
refresh_token: str = secrets.token_urlsafe()
print(access_token)
return jsonify(
{
"access_token": access_token,
"refresh_token": refresh_token,
"status": "success",
}
)
return jsonify({"status": "login failed"}), 401
@app.route("/movies", methods=["GET"])
def get_movies() -> Response:
"""
Get all movies
"""
return jsonify(movies)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=19003)