Ejemplo n.º 1
0
def login():
    if request.method == 'POST':
        # get authetication
        username = request.form['username']
        password = request.form['password']

        # print(username, password)

        db = Pysql()

        # 0 - Admin
        res = db.selectAll(sql="""
            select * from user where username=%s and role=0;
        """,
                           params=(username, ))

        if res["success"] == True:
            if res["count"] == 0:
                return jsonify(success=False,
                               reason="Wrong password/username!")
            else:
                d = res["data"][0]
                if password != d["password"]:
                    return jsonify(success=False,
                                   reason="Wrong password/username!")
                else:
                    return jsonify(success=True, data=d)
        else:
            return jsonify(success=False, reason="Internal wrong!")

    elif request.method == 'GET':
        # return login page
        return render_template('login.html')
Ejemplo n.º 2
0
def getUserName(id):
    # get user name by id
    db = Pysql()

    res = db.selectAll(sql="""
        select username from user where id=%s;
    """,
                       params=(id, ))

    if res["success"] == True and res["count"] > 0:
        return res["data"][0]["username"]
    else:
        return ""
Ejemplo n.º 3
0
def getAllProducts():
    db = Pysql()

    res = db.selectAll(sql="""
        select * from product;
    """)

    if res["success"] == True:
        return jsonify(success=True,
                       html=render_template("producttable.html",
                                            products=res["data"]))
    else:
        return jsonify(success=False, reason="Internal Wrong!")
Ejemplo n.º 4
0
def getFirstCats():
    db = Pysql()

    res = db.selectAll(sql="""
        select * from category where parent_id=0;
    """)

    if res["success"] == True:
        return jsonify(success=True,
                       html=render_template("typecontainer.html",
                                            hier=0,
                                            catCount=res["count"],
                                            cats=res["data"],
                                            parent_id=0))
    else:
        return jsonify(success=False, reason="Internal Wrong!")
Ejemplo n.º 5
0
def getCatName(id):
    # get category name by id
    db = Pysql()

    if int(id) == 0:
        return "根节点"

    res = db.selectAll(sql="""
        select name from category where id=%s;
    """,
                       params=(id, ))

    if res["success"] == True and res["count"] > 0:
        return res["data"][0]["name"]
    else:
        return False
Ejemplo n.º 6
0
def orderlist():
    if authenticationCheck(request.cookies) == True:
        username = request.cookies.get("username")

        db = Pysql()

        res = db.selectAll(sql="""
            select * from `order`;
        """)

        if res["success"] == True:
            return render_template('orderlist.html',
                                   username=username,
                                   orders=res["data"])
        else:
            return jsonify(success=False, reason="Internal Wrong!")

    else:
        return redirect(url_for("login"))
Ejemplo n.º 7
0
def getFollowingCats(hier, id):
    parent_id = int(id)
    curHier = int(hier) + 1

    db = Pysql()

    res = db.selectAll(sql="""
        select * from category where parent_id=%s;
    """,
                       params=(parent_id, ))

    if res["success"] == True:
        return jsonify(success=True,
                       html=render_template("typecontainer.html",
                                            hier=curHier,
                                            catCount=res["count"],
                                            cats=res["data"],
                                            parent_id=parent_id))
    else:
        return jsonify(success=False, reason="internal Wrong!")
Ejemplo n.º 8
0
def getCatDetail(id):
    id = int(id)

    db = Pysql()

    res = db.selectAll(sql="""
        select * from category where id=%s;
    """,
                       params=(id, ))

    parent_id = res["data"][0]["parent_id"]
    created_uid = res["data"][0]["created_user"]
    updated_uid = res["data"][0]["updated_user"]

    if res["success"] == True:
        return jsonify(success=True,
                       html=render_template(
                           "typedetailcontainer.html",
                           item=res["data"][0],
                           parent_name=getCatName(parent_id),
                           created_user=getUserName(created_uid),
                           updated_user=getUserName(updated_uid)))
    else:
        return jsonify(success=False, reason="Internal Wrong!")