增加 web 目录
This commit is contained in:
@@ -84,6 +84,7 @@ class UserJob:
|
||||
if self.is_first_time() or not self.check_user_is_login():
|
||||
self.is_ready = False
|
||||
if not self.handle_login(): return
|
||||
self.set_last_heartbeat()
|
||||
|
||||
self.is_ready = True
|
||||
self.user_did_load()
|
||||
@@ -113,7 +114,7 @@ class UserJob:
|
||||
|
||||
def handle_login(self):
|
||||
UserLog.print_start_login(user=self)
|
||||
self.login()
|
||||
return self.login()
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
|
||||
0
py12306/web/__init__.py
Normal file
0
py12306/web/__init__.py
Normal file
0
py12306/web/handler/__init__.py
Normal file
0
py12306/web/handler/__init__.py
Normal file
17
py12306/web/handler/user.py
Normal file
17
py12306/web/handler/user.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from flask import Blueprint, request
|
||||
from flask.json import jsonify
|
||||
from flask_jwt_extended import (
|
||||
JWTManager, jwt_required, create_access_token,
|
||||
get_jwt_identity)
|
||||
|
||||
user = Blueprint('user', __name__)
|
||||
|
||||
|
||||
@user.route('/login', methods=['POST'])
|
||||
def login():
|
||||
username = request.json.get('username', None)
|
||||
password = request.json.get('password', None)
|
||||
if username and password and username == '1':
|
||||
access_token = create_access_token(identity=username)
|
||||
return jsonify(access_token=access_token)
|
||||
return jsonify({"msg": "用户名或密码错误"}), 401
|
||||
27
py12306/web/web.py
Normal file
27
py12306/web/web.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
|
||||
from flask import Flask, request
|
||||
from flask_jwt_extended import (
|
||||
JWTManager, jwt_required, create_access_token,
|
||||
get_jwt_identity)
|
||||
|
||||
from py12306.web.handler.user import user
|
||||
|
||||
app = Flask(__name__)
|
||||
app.register_blueprint(user)
|
||||
|
||||
# app.config['JWT_TOKEN_LOCATION'] = ['json']
|
||||
app.config['JWT_SECRET_KEY'] = 'super-secret' # Change this!
|
||||
jwt = JWTManager(app)
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def test():
|
||||
print(111111)
|
||||
|
||||
def run(port=8080):
|
||||
app.run(debug=True, port=port if port else 8080, host='0.0.0.0')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
Reference in New Issue
Block a user