You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

4 years ago
from flask import Flask, request, make_response
import json
import dao
import sr_jwt as jwt
app = Flask(__name__)
@app.route('/login', methods=['POST'])
def login():
cookie_jwt = request.cookies.get('jwt')
if cookie_jwt is not None:
if jwt.check_jwt(cookie_jwt):
return make_response(json.dumps({'result': 'success'}))
rdata = json.loads(request.data.decode()) # request data
username = rdata['username']
password = rdata['password']
if dao.valid(username, password):
return make_response(json.dumps({'result': 'success'})).set_cookie('jwt', jwt.generate_jwt(username))
else:
return make_response(json.dumps({'result': 'fail'}))
@app.route('/register', methods=['POST'])
def register():
cookie_jwt = request.cookies.get('jwt')
rdata = json.loads(request.data.decode()) # request data
username = rdata['username']
program_type = rdata['program_type']
program_name = rdata['program_name']
if cookie_jwt is not None:
if jwt.check_jwt(cookie_jwt):
if dao.register(username, program_type, program_name):
return make_response(json.dumps({'result': 'success'}))
return make_response(json.dumps({'result': 'fail'}))
if __name__ == '__main__':
app.run()