50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
from flask import Flask, redirect, url_for, session, g
|
|
from flask_httpauth import HTTPTokenAuth
|
|
from flask_cors import CORS
|
|
from func.config import SECRET_KEY
|
|
|
|
import func.login
|
|
import func.index
|
|
|
|
app = Flask(__name__)
|
|
app.config["SECRET_KEY"] = SECRET_KEY
|
|
app.config["JSON_AS_ASCII"] = False
|
|
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
|
app.config['SESSION_COOKIE_SECURE'] = False
|
|
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
|
CORS(app, supports_credentials=True)
|
|
auth = HTTPTokenAuth(scheme='Bearer')
|
|
|
|
@app.before_request
|
|
def before_request():
|
|
g.user = None
|
|
if 'user_id' in session:
|
|
g.user = session.get('user_id')
|
|
|
|
@app.route("/")
|
|
def home():
|
|
return redirect(url_for('index'))
|
|
|
|
@app.route("/index", methods=['GET'])
|
|
def index():
|
|
return func.index.index()
|
|
|
|
@app.route("/modify", methods=['POST'])
|
|
def modify():
|
|
return func.index.modify()
|
|
|
|
@app.route("/login", methods=['GET', 'POST'])
|
|
def login():
|
|
return func.login.login()
|
|
|
|
@app.route('/logout')
|
|
def logout():
|
|
return func.index.logout()
|
|
|
|
if __name__ == "__main__":
|
|
app.run(
|
|
host="0.0.0.0",
|
|
port=8889,
|
|
debug=True
|
|
)
|