Example #1
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        merchant = DB.session.query(Merchant).filter(
            Merchant.username == args.username).first()
        if merchant is None:
            return CommonUtil.json_response(-1, "用户名不存在")

        if merchant.password == CommonUtil.create_user_password(
                args.username, args.password):
            # 生成新token
            merchant.token = CommonUtil.create_admin_token(args.username)
            DB.session.commit()

            merchant = DB.session.query(Merchant).filter(
                Merchant.username == args.username).first()
            dic = {'token': fields.String}

            return CommonUtil.json_response(0, "登录成功", marshal(merchant, dic))
        else:
            print(merchant.password)
            print(CommonUtil.create_user_password(args.username,
                                                  args.password))
            return CommonUtil.json_response(-1, "密码错误")
Example #2
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('secret_key', required=True)
        parser.add_argument('order_no', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        order = DB.session.query(Order).filter(
            Order.order_no == args.order_no).first()
        if order is None:
            return CommonUtil.json_response(-1, '订单不存在')

        if order.confirm_secret_key != args.secret_key:
            return CommonUtil.json_response(-1, '订单密钥错误')

        if order.confirm_at:
            return CommonUtil.json_response(-1, '订单已确认过')

        merchant = DB.session.query(Merchant).filter(
            Merchant.id == order.merchant_id).first()
        # 二次密码核对
        if merchant and merchant.password == CommonUtil.create_user_password(
                merchant.username, args.password):
            stock = DB.session.query(ProductStock).\
                filter(order.product_id == ProductStock.product_id).\
                filter(ProductStock.sold_at == None). \
                first()
            if stock:
                stock.sold_at = CommonUtil.time_format_str()
                stock.order_id = order.id
                DB.session.commit()

                order.confirm_at = CommonUtil.time_format_str()
                DB.session.commit()

                info = '<div style="display:flex;justify-content:center"><div style="width:375px"><div><p style="color:#000;font-size:40px;font-weight:700">“</p><p style="color:#333;font-size:14px;line-height:20px;letter-spacing:2px">%s</p><p style="color:#000;font-size:40px;font-weight:700;text-align:right">”</p></div><div style="margin-top:140px;display:flex;justify-content:center"><span style="color:#999;font-size:10px">Copyright@2018 51shuaba.xyz All Rights Reseved.</span></div></div></div>' % (
                    stock.content)

                result = EmailUtil.send_html_email(
                    '订单' + args.order_no + '发货通知', info, order.from_email)

                if result is True:
                    return CommonUtil.json_response(0, '确认成功,已邮件通知买家')
                else:
                    return CommonUtil.json_response(0, '确认成功,但是发货邮件未能送达,请联系买家')
            else:
                return CommonUtil.json_response(-1, '库存不足')

        return CommonUtil.json_response(-1, '密码错误')
Example #3
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        parser.add_argument('password2', required=True)
        parser.add_argument('validId', required=True)
        parser.add_argument('validValue', required=True)
        args = parser.parse_args()

        # 效验验证码
        result = CheckUtil.check_valid_image(args.validId, args.validValue)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_username(args.username) is None:
            return CommonUtil.json_response(-1, "用户名必须是6-16位英文或数字")

        if Valid.is_password(args.password) is None:
            return CommonUtil.json_response(-1, "密码必须是6-16位英文或数字")

        if args.password != args.password2:
            return CommonUtil.json_response(-1, "两次密码不一致")

        merchant = DB.session.query(Merchant).filter(
            Merchant.username == args.username).first()
        if merchant:
            return CommonUtil.json_response(-1, "用户名已存在")

        # 生成唯一的商户id
        merchant_no = None
        while merchant_no is None:
            random_id = CommonUtil.random_id()
            merchant = DB.session.query(Merchant).filter(
                Merchant.merchant_no == random_id).first()
            if merchant is None:
                merchant_no = random_id

        merchant = Merchant(merchant_no=merchant_no,
                            username=args.username,
                            password=CommonUtil.create_user_password(
                                args.username, args.password),
                            create_at=CommonUtil.time_format_str(),
                            create_ip=request.environ['REMOTE_ADDR'],
                            is_frozen=0)
        DB.session.add(merchant)
        DB.session.commit()
        return CommonUtil.json_response(0, "注册成功")
Example #4
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        user = DB.session.query(User).filter(
            User.username == args.username).first()
        if user is None:
            return CommonUtil.json_response(-1, "用户不存在")

        if user.password == CommonUtil.create_user_password(
                args.username, args.password):
            # 生成新token
            user.token = CommonUtil.create_user_token(args.username)
            DB.session.commit()

            user = DB.session.query(User).filter(
                User.username == args.username).first()
            dic = {
                'token': fields.String,
                'user_id': fields.String,
                'username': fields.String,
                'phone': fields.String,
                'email': fields.String,
                'expire_at': fields.String,
                'last_login_ip': fields.String,
                'last_login_time': fields.String,
                'real_name': fields.String,
                'id_card': fields.String,
                'address': fields.String,
                'create_at': fields.String,
                'nike_name': fields.String,
                'is_identity': fields.String,
                'avatar': fields.String,
                'sex': fields.String
            }

            return CommonUtil.json_response(0, "登录成功", marshal(user, dic))
        else:
            return CommonUtil.json_response(-1, "密码错误")
Example #5
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        user = DB.session.query(User).filter(
            User.username == args.username).first()
        if user is None:

            now = int(time.time())

            user = User(user_id=CommonUtil.md5(now),
                        username=args.username,
                        password=CommonUtil.create_user_password(
                            args.username, args.password))
            DB.session.add(user)
            DB.session.commit()

            return CommonUtil.json_response(0, '注册成功')
        else:
            return CommonUtil.json_response(-1, '用户已存在')