Esempio n. 1
0
def login():
    if request.method == "GET":
        return ops_render("member/login.html")
    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON("请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON("请输入正确的登录密码~~")
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -1~~")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -2 ~~")

    if user_info.status != 1:
        return ops_renderErrJSON("账号被禁用,请联系管理员处理~~")
    # session['uid'] = user_info.id

    response = make_response(ops_renderJSON(msg="登录成功~~"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.id),
        60 * 60 * 24 * 120)
    return response
def login():
    if request.method == "GET":
        return ops_render("member/login.html")
    elif request.method == "POST":
        req = request.values
        name = req["name"] if "name" in req else ""
        password = req["password"] if "password" in req else ""

        if name is None or len(name) < 1:
            return ops_renderErrJSON(msg="请输入正确的用户名")
        if password is None or len(password) < 6:
            return ops_renderErrJSON(msg="请输入正确的密码")

        user_info = User.query.filter_by(name=name).first()
        if not user_info:
            return ops_renderErrJSON(msg="请输入正确的登录用户名和密码(user not found)")

        if user_info.password != UserService.gene_pwd(password):
            return ops_renderErrJSON(msg="请输入正确的登录用户名和密码(error password)")

        response = make_response(ops_renderJSON(msg="登录成功~"))
        response.set_cookie(
            app.config["AUTH_COOKIE_NAME"],
            "%s#%s" % (UserService.gene_auth_code(user_info), user_info.id),
            60 * 60 * 24)
        return response
Esempio n. 3
0
def reg():
    if request.method == "GET":
        return render_template("member/reg.html")
    else:
        req = request.values
        nickname = req['nickname'] if "nickname" in req else ""
        login_name = req['login_name'] if "login_name" in req else ""
        login_pwd = req['login_pwd'] if "login_pwd" in req else ""
        login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""
        if login_name is None or len(login_name) < 1:
            return ops_renderErrJSON(msg="请输入正确的登录用户名~~")

        if login_pwd is None or len(login_pwd) < 6:
            return ops_renderErrJSON(msg="请输入正确的登录密码,并且不能小于6个字符~~")

        if login_pwd != login_pwd2:
            return ops_renderErrJSON(msg="请输入正确的确认登录密码~~")

        # 查询user用户名
        user_info = User.query.filter_by(login_name=login_name).first()
        print(user_info)
        if user_info:
            return ops_renderErrJSON(msg="登录用户名已被注册,请换一个~~")
        model_user = User()
        model_user.login_name = login_name
        model_user.nickname = nickname if nickname is not None else login_name
        model_user.login_salt = UserService.geneSalt(8)
        model_user.login_pwd = UserService.genePwd(login_pwd,
                                                   model_user.login_salt)
        model_user.created_time = model_user.updated_time = getCurrentTime()
        db.session.add(model_user)
        db.session.commit()

        return ops_renderJSON(msg="注册成功~~")
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")
    elif request.method == "POST":
        req = request.values
        name = req["name"] if "name" in req else ""
        type = req["type"] if "type" in req else ""
        password = req["password"] if "password" in req else ""
        password2 = req["password2"] if "password2" in req else ""

        if name is None or len(name) < 1:
            return ops_renderErrJSON(msg="请输入正确的用户名")
        if type is None or len(type) < 1:
            return ops_renderErrJSON(msg="请选择正确的类型")

        if password is None or len(password) < 6:
            return ops_renderErrJSON(msg="请输入正确的密码")

        if password2 != password2:
            return ops_renderErrJSON(msg="两次密码不一致")

        user_info = User.query.filter_by(name=name).first()
        if user_info:
            return ops_renderErrJSON(msg="用户名已被注册,请更换用户名重新注册")

        model_user = User()
        model_user.name = name
        model_user.type = type
        model_user.password = UserService.gene_pwd(password)
        model_user.regist_time = get_current_time()
        db.session.add(model_user)
        db.session.commit()
        return ops_renderJSON(msg="注册成功~")
def send_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["经销商"] and com.seller != g.current_user.id:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["待发货"]:
        return ops_renderErrJSON(msg="只能发货已下单的商品")
    com.status = "已发货"
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "发货")
    return ops_renderJSON(msg="发货成功")
def del_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["经销商"] and com.seller != g.current_user.id:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["出售中"]:
        return ops_renderErrJSON(msg="只能下架销售中的商品")

    ComService.delete_com(com_id)
    ComService.do_ops(g.current_user.id, com_id, "下架")
    return ops_renderJSON(msg="下架成功")
def sale_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["超市管理员"] and com.buyer != g.current_user.id:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["已分发"]:
        return ops_renderErrJSON(msg="只能销售已分发的商品")
    com.status = "已销售"
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "销售")
    return ops_renderJSON(msg="销售成功")
def trans_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["运输商"]:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["已发货"]:
        return ops_renderErrJSON(msg="只能运输已发货的商品")
    com.status = "运输中"
    com.trans = g.current_user.id
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "运输")
    return ops_renderJSON(msg="运输成功")
def warehouse_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["仓库管理员"]:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["运输中"]:
        return ops_renderErrJSON(msg="只能入库运输中的商品")
    com.status = "已入库"
    com.warehouse = g.current_user.id
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "入库")
    return ops_renderJSON(msg="入库成功")
def buy_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["超市管理员"]:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["出售中"]:
        return ops_renderErrJSON(msg="商品已被购买")

    com.status = "待发货"
    com.buyer = g.current_user.id
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "下单")
    return ops_renderJSON(msg="下单成功")
def distribution_com():
    req = request.values
    com_id = req["id"] if "id" in req else ""
    com = ComService.find_com_by_id(com_id)
    if g.current_user.type not in ["仓库管理员"
                                   ] and com.warehouse != g.current_user.id:
        return ops_renderErrJSON("您无权执行此操作")
    if com is None:
        return ops_renderErrJSON(msg="该商品不存在")
    if com.status not in ["已入库"]:
        return ops_renderErrJSON(msg="只能分发已入库的商品")
    com.status = "已分发"
    com.warehouse = g.current_user.id
    db.session.commit()
    ComService.do_ops(g.current_user.id, com_id, "分发")
    return ops_renderJSON(msg="分发成功")
def add():
    req = request.values
    name = req["name"] if "name" in req else ""
    origin = req["origin"] if "origin" in req else ""

    if name is None or len(name) < 1:
        return ops_renderErrJSON(msg="请输入正确的商品名")
    if origin is None or len(origin) < 1:
        return ops_renderErrJSON(msg="请输入正确的产地")

    model_com = Commodity()

    model_com.name = name
    model_com.origin = origin
    model_com.status = "出售中"
    model_com.seller = g.current_user.id
    db.session.add(model_com)
    db.session.commit()

    com_info = Commodity.query.order_by(
        Commodity.id.desc()).filter_by(name=name).first()
    ComService.do_ops(g.current_user.id, com_info.id, "上架")
    return ops_renderJSON(msg="上架成功")