| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- #!/usr/bin/python3
- import sys
- import os
- from flask import render_template, url_for
- from app import app
- from flask import request, jsonify, send_from_directory
- from flask_restful import Resource, Api
- import PopufareAPI as api
- @app.route('/favicon.ico')
- def favicon():
- return send_from_directory(os.path.join(app.root_path, 'static'),
- 'favicon.ico',
- mimetype='favicon.ico')
- @app.route("/api/v1/User")
- def api_user():
- field_names = [ "username", "first_name", "last_name",
- "email", "phone", "address", "city", "state", "zip",
- "shipping_name", "shipping_address", "shipping_address",
- "shipping_zip", "password"];
- args = request.args
- res = {}
- print("....", args)
- if 'action' in args:
- if args['action'] == 'add':
- api_req = { "action":"add", "function":"User" }
- for f in field_names:
- if f in args:
- api_req[f] = args[f]
- print("avpi/v1/User send:", api_req)
- res = api.Request(api_req)
- print("got:...", res)
- elif args['action'] == 'get':
- print(">>>cp")
- api_req = { "action":"get", "function":"User" }
- if "userid" in args:
- api_req["userid"] = args["userid"]
- print("avpi/v1/User.get send:", api_req)
- res = api.Request(api_req)
- return jsonify(res)
- @app.route("/api/v1/Card")
- def api_card():
- field_names = [ "logical_card_id", "mag_token", "rfid_token", "userid" ]
- args = request.args
- res = {}
- print("api.card args:", args)
- if 'action' in args:
- if args['action'] == 'add':
- api_req = { "action":"add", "function":"Card" }
- for f in field_names:
- if f in args:
- api_req[f] = args[f]
- print("avpi/v1/Card send:", api_req)
- res = api.Request(api_req)
- print("got:...", res)
- elif args['action'] == 'update':
- api_req = { "action":"update", "function":"Card" }
- if "userid" in args:
- api_req["userid"] = args["userid"]
- if "logical_card_id" in args:
- api_req["logical_card_id"] = args["logical_card_id"]
- print("avpi/v1/Card.update send:", api_req)
- res = api.Request(api_req)
- return jsonify(res)
- @app.route("/api/v1/CardInfo")
- def api_card_info():
- res = {}
- args = request.args
- print("....", args)
- if 'action' in args:
- if args['action'] == 'search':
- api_req = { "action":"search", "function":"CardInfo" }
- search_fields = ["logical_card_id", "mag_token", "rfid_token"]
- for sf in search_fields:
- if sf in args:
- api_req[sf] = args[sf]
- res = api.Request(api_req)
- print("got:...", res)
- return jsonify(res)
- @app.route("/api/v1/UserInfo")
- def api_user_info():
- res = {}
- args = request.args
- print("....", args)
- userid=-1
- if "userid" in args:
- userid = args["userid"]
- api_req = { "function":"UserInfo", "userid":userid }
- print("sending...", api_req)
- res = api.Request(api_req)
- print("got:...", res)
- return jsonify(res)
- @app.route("/")
- @app.route("/index")
- def index():
- usr = { "username":"clementine", "content" : "index" }
- return render_template( usr["content"] + '.html', title='home', user=usr)
- @app.route("/manage_card")
- def manage_card():
- usr = { "username":"clementine" }
- return render_template( 'manage_card.html', title='home', user=usr)
- @app.route("/manage_user")
- def manage_user():
- usr = { "username":"clementine" }
- return render_template( 'manage_user.html', title='home', user=usr)
- @app.route("/create_user")
- def create_user():
- usr = { "username":"clementine" }
- return render_template( 'create_user.html', title='home', user=usr)
- @app.route("/reissue_card")
- def reissue_card():
- usr = { "username":"clementine" }
- return render_template( 'reissue_card.html', title='home', user=usr)
- @app.route("/recycle_card")
- def recycle_card():
- usr = { "username":"clementine" }
- return render_template( 'recycle_card.html', title='home', user=usr)
- @app.route("/add_card_block")
- def add_card_block():
- usr = { "username":"clementine" }
- return render_template( 'add_card_block.html', title='home', user=usr)
- @app.route("/process_pending_card")
- def process_pending_card():
- usr = { "username":"clementine" }
- return render_template( 'process_pending_card.html', title='home', user=usr)
- @app.route("/search")
- def search():
- usr = { "username":"clementine" }
- return render_template( 'search.html', title='home', user=usr)
- @app.route("/help")
- def help():
- usr = { "username":"clementine" }
- return render_template( 'help.html', title='home', user=usr)
- @app.route("/api/v1/hello")
- def api_hello():
- #data = { "version":"v1", "type":"hello", "data":"hello" }
- sessid = request.cookies.get('sessionid')
- uname = request.cookies.get('username')
- sess_data = { "sessionid":sessid, "username":uname }
- data = popfareapi.hello(sess_data)
- return jsonify(data)
- ###
- #class Database:
- # def __init__(self):
- # host = "127.0.0.1"
- # user = "bus"
- # password = ""
- # db = "busdb"
- #
- # self.con = pymysql.connect(host=host, user=user, db=db, cursorclass=pymysql.cursors.DictCursor)
- # self.cur = self.con.cursor()
- #
- # def ok(self):
- # self.cur.execute("select rulename from rule_class where id = %s", 1)
- # res = self.cur.fetchall()
- # return res
- #
- #@app.route("/api/v1/card")
- #def api_card():
- #
- # print(request.args)
- # param = request.args
- #
- # cardid = param.get("id")
- # mag_token = param.get("mag_token")
- # rfid_token = param.get("rfid_token")
- #
- # db = Database()
- # ok = db.ok()
- #
- # print(ok)
- #
- # if cardid:
- # print("cardid:", cardid)
- # elif mag_token:
- # print("mag:", mag_token)
- # elif rfid_token:
- # print("rfid:", rfid_token)
- #
- #
- # return jsonify({ "message": "card not implemented"})
- #
- #@app.route("/api/v1/user")
- #def api_user():
- # return jsonify({ "message": "user not implemented"})
- #
- #@app.route("/api/v1/pass")
- #def api_pass():
- # return jsonify({ "message": "pass not implemented"})
- #
- #@app.route("/api/v1/group")
- #def api_group():
- # return jsonify({ "message": "group not implemented"})
|