Beispiel #1
0
    def post(self, request):
        try:
            goods_id = request.data['goods_id']
        except KeyError:
            return error_request(ErrBaseParams)

        self.check_bid(request)

        goods = Goods.objects.filter(goods_id=goods_id).first()
        balance = Balance.objects.filter(user__username=request.user).first()

        if not balance or not goods:
            self.remove_bid(request)
            return error_request(ErrBaseServer)

        if not self.can_bid(goods, balance):
            self.remove_bid(request)
            return error_request(ErrGoodsBid)

        balance.balance -= goods.step_price
        goods.now_price += 0.1
        balance.save()
        goods.save()
        self.remove_bid(request)
        return_data = normal_success()
        return_data['msg'] = '出价成功'
        return success_request(return_data)
Beispiel #2
0
    def post(request):
        try:
            phone = request.data['phone']
            password = request.data['password']
        except KeyError:
            return error_request(ErrBaseParams)

        if not is_phone(phone):
            return error_request(ErrBaseParams)

        if not is_password(password):
            return error_request(ErrBaseParams)

        user = Profile.objects.filter(phone=phone).first()

        if not user:
            return error_request(ErrUserDoesNotExist)

        if not check_password(password, user.password):
            return error_request(ErrUserPasswordIncorrect)

        return_data = dict_success()
        return_data['msg'] = '登录成功'
        return_data['data'] = serializer_data(user, ProfileSerializer, request)
        return_data['data']['token'] = jwt_encode_handler(
            jwt_payload_handler(user))
        return success_request(return_data)
Beispiel #3
0
    def get(request):
        try:
            category_id = request.query_params['category_id']
        except KeyError:
            return error_request(ErrBaseParams)

        goods_list = Goods.objects.filter(category_id=int(category_id))
        if not goods_list:
            return error_request(ErrBaseNotData)

        return_data = array_success()
        return_data['data'] = serializer_list_data(goods_list,
                                                   GoodsCategorySerializer,
                                                   request)
        return success_request(return_data)
Beispiel #4
0
    def check_bid(self, request):
        # 检查是否在支付数组里面
        if request.user in bid_array:
            return error_request(ErrGoodsBidding)

        # 添加对象到支付数组
        bid_array.append(request.user)
Beispiel #5
0
    def get(self, request):
        try:
            msg_id = request.query_params['msg_id']
        except KeyError:
            return error_request(ErrBaseParams)

        msg = Msg.objects.filter(pk=msg_id).first()

        if not msg:
            return error_request(ErrBaseNotData)

        if self.check_object_permissions(request, msg_id):
            return error_request(ErrBaseIllegalPermission)

        return_data = dict_success()
        return_data['data'] = MsgSerializer(msg).data
        return success_request(return_data)
Beispiel #6
0
    def post(request):
        try:
            # get
            platform = request.query_params['platform']
            device_id = request.query_params['device_id']

            # post
            phone = request.data['phone']
            password = request.data['password']
            code = request.data['code']
        except KeyError:
            return error_request(ErrBaseParams)

        if not is_phone(phone):
            return error_request(ErrBaseParams)

        if not is_password(password):
            return error_request(ErrBaseParams)

        if not is_code(code):
            return error_request(ErrBaseParams)

        exists = Profile.objects.filter(phone=phone).exists()

        if exists:
            return error_request(ErrUserDoesExist)

        user = Profile.objects.create(
            uid=gen_uid(),
            phone=phone,
            password=make_password(password),
            platform=platform,
            username='******' + phone,
            register_ip=gen_ip(request),
            device_id=device_id,
        )

        Balance.objects.create(user=user, )

        return_data = dict_success()
        return_data['msg'] = '注册成功'
        return_data['data'] = serializer_data(user, ProfileSerializer, request)
        return_data['data']['token'] = jwt_encode_handler(
            jwt_payload_handler(user))
        return success_request(return_data)
Beispiel #7
0
    def get(request):
        try:
            goods_id = request.query_params['goods_id']
        except KeyError:
            return error_request(ErrBaseParams)

        goods = Goods.objects.filter(goods_id=goods_id).first()

        if not goods:
            return error_request(ErrBaseNotData)

        goods_image_list = GoodsImage.objects.filter(goods_id=goods.id).all()
        return_data = dict_success()
        return_data['data'] = serializer_data(goods, GoodsDetailSerializer,
                                              request)
        return_data['data']['goods_images'] = serializer_list_data(
            goods_image_list, GoodsImageSerializer, request)
        return success_request(return_data)
Beispiel #8
0
    def get(request):
        user = Profile.objects.filter(username=request.user).first()

        if not user:
            return error_request(ErrUserDoesNotExist)

        return_data = dict_success()
        return_data['data'] = serializer_data(user, ProfileSerializer, request)
        return success_request(return_data)
Beispiel #9
0
    def post(request):
        try:
            phone = request.data['phone']
            password = request.data['password']
            code = request.data['code']
        except KeyError:
            return error_request(ErrBaseParams)

        if not is_code(code):
            return error_request(
                ErrVerificationCodeForResettingThePasswordIsIncorrect)

        user = Profile.objects.filter(phone=phone).first()
        user.password = make_password(password)
        user.save()

        return_data = normal_success()
        return_data['msg'] = '重置成功'
        return success_request(return_data)
Beispiel #10
0
 def get(request):
     br_list = BidRecord.objects.filter(
         profile__username=request.user).all()
     if not br_list:
         return error_request(ErrBaseNotData)
     return_data = array_success()
     return_data['data'] = serializer_list_data(br_list,
                                                IAmShootingSerializer,
                                                request)
     return success_request(return_data)
Beispiel #11
0
    def get(request):
        goods_list = Goods.objects.filter(is_new=True).all()

        if not goods_list:
            return error_request(ErrBaseNotData)

        return_data = array_success()
        return_data['data'] = serializer_list_data(goods_list,
                                                   RecommendSerializer,
                                                   request)
        return success_request(return_data)
Beispiel #12
0
    def get(request):
        goods_list = Goods.objects.all()

        if not goods_list:
            return error_request(ErrGoodsNotFound)

        return_data = array_success()
        return_data['data'] = serializer_list_data(goods_list,
                                                   GoodsDetailSerializer,
                                                   request)
        return success_request(return_data)
Beispiel #13
0
    def get(request):
        collection = Collection.objects.filter(
            user__username=request.user).all()

        if not collection:
            return error_request(ErrBaseNotData)

        return_data = array_success()
        data = serializer_list_data(collection, MyCollectionSerializer,
                                    request)
        print(data)
        return_data['data'] = None
        return success_request(return_data)
Beispiel #14
0
    def get(request):
        banner_list = Banner.objects.all()
        topic_list = Topic.objects.all()

        if not banner_list and not topic_list:
            return error_request(ErrBaseNotData)

        return_data = dict_success()
        return_data['data']['banner'] = serializer_list_data(
            banner_list, BannerSerializer, request)
        return_data['data']['topic'] = serializer_list_data(
            topic_list, TopicSerializer, request)
        return success_request(return_data)
Beispiel #15
0
    def post(request):
        try:
            old_password = request.data['old_password']
            new_password = request.data['new_password']
        except KeyError:
            return error_request(ErrBaseParams)

        if not is_password(new_password):
            return error_request(ErrBaseParams)

        if old_password == new_password:
            return error_request(ErrUserSamePassword)

        user = Profile.objects.filter(username=request.user).first()

        if not check_password(old_password, user.password):
            return error_request(ErrUserPasswordIncorrect)

        user.password = make_password(new_password)
        user.save()

        return_data = normal_success()
        return_data['msg'] = '修改成功'
        return success_request(return_data)
Beispiel #16
0
    def get(request):
        msg_array = []
        msg_list = MsgHandler.objects.filter(
            receiver__username=request.user.username).all()

        for msg in msg_list:
            msg_array.append(Msg.objects.filter(pk=msg.msg_id).first())

        if not msg_array:
            return error_request(ErrBaseNotData)

        return_data = array_success()
        return_data['data'] = (MsgListSerializer(value).data
                               for value in msg_array)
        return success_request(return_data)
Beispiel #17
0
 def check_in_login_zone(self, oauth_from):
     if oauth_from not in self.login_zone:
         return False, error_request(ErrUserNotSupportedForLogin)
Beispiel #18
0
    def post(self, request):
        try:

            # get
            platform = request.query_params['platform']
            device_id = request.query_params['device_id']

            # post
            gender = request.data['gender']
            oauth_from = request.data['oauth_from']
            oauth_openid = request.data['open_id']
            access_token = request.data['token']
            nick = request.data['nick']
            avatar = request.data['avatar']

            gender = int(gender)

        except KeyError:
            return error_request(ErrBaseParams)
        except ValueError:
            return error_request(ErrBaseParams)

        is_in_login_zone, return_data = self.check_in_login_zone(oauth_from)
        if not is_in_login_zone:
            return return_data

        is_valid, oauth_userinfo = self.validate_and_get_userinfo(
            oauth_from, access_token, oauth_openid)

        if not is_valid:
            return error_request(ErrUserNotAccessTheValidate)

        user = Profile.objects.filter(oauth_openid=oauth_openid).first()
        if user:
            return_data = dict_success()
            return_data['msg'] = '登录成功'
            return_data['data'] = serializer_data(user, ProfileSerializer,
                                                  request)
            return_data['data']['token'] = jwt_encode_handler(
                jwt_payload_handler(user))
            return success_request(return_data)

        user = Profile.objects.create(uid=gen_uid(),
                                      username=self.username,
                                      nick=self.clear_nick(nick),
                                      register_ip=gen_ip(request),
                                      device_id=device_id,
                                      platform=platform,
                                      avatar=avatar,
                                      gender=gender,
                                      oauth_openid=oauth_openid,
                                      oauth_from=oauth_from,
                                      oauth_userinfo=oauth_userinfo,
                                      oauth_time=datetime.now())
        Balance.objects.create(user=user, )
        return_data = dict_success()
        return_data['msg'] = '登录成功'
        return_data['data'] = serializer_data(user, ProfileSerializer, request)
        return_data['data']['token'] = jwt_encode_handler(
            jwt_payload_handler(user))
        return success_request(return_data)