增加 web 目录

This commit is contained in:
Jalin
2019-01-12 12:16:11 +08:00
parent d5097d2374
commit a337f972a8
5 changed files with 46 additions and 1 deletions

View File

@@ -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
View File

View File

View 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
View 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()