示例#1
0
    def get(self):
        """
        @apiDescription 用户登出
        @api {get} /logout/? 登出
        @apiGroup login

        @apiError UserNotLogin 用户未登录
        @apiError UserNotExists 用户不存在
        """
        _uid = self.get_current_user()
        if not _uid:
            self.write(dict(
                status=1,
                msg="user does not logined",
            ))
            return

        user = User.get_instance_by_id(self.orm_session, _uid)
        if not user:
            self.write(dict(
                status=1,
                msg="user does not exist",
            ))
            return

        self.redis_session.delete(self.sid)
        self.clear_cookie("sid")
        self.write({})
示例#2
0
    def get(self, uid):
        """
        @apiDescription 获取用户信息
        @api {get} /user/([0-9]+)/? 获取用户信息
        @api {get} /shop/([0-9]+)/? 获取商家信息
        @apiGroup user
        @apiGroup shop

        @apiParam {Number} uid 用户uid

        @apiPermission user

        @apiSuccess {Number} uid 用户uid
        @apiSuccess {String} avatar 头像
        @apiSuccess {String} name 用户名
        @apiSuccess {Number} speed 配送时间,仅商家时出现
        @apiSuccess {Number} sales_count 销量,仅商家出现
        @apiSuccess {Number} lowest_money 起送价,仅商家出现
        @apiSuccess {Boolean} invoice 是否开具发票,仅商家出现
        @apiSuccess {Boolean} free_send 是否免费配送,如果非免费配送,统一收配送费1元
        @apiSuccess {Integer} distance 距离,仅商家出现
        @apiSuccess {Boolean} new_seller 是否为新商家,仅商家出现
        @apiSuccess {Number} level 用户级别,仅获取自己信息时出现
        @apiSuccess {String} register_at 注册时间,仅获取自己信息时出现
        @apiSuccess {String} phone 手机号,仅获取自己信息时出现
        @apiSuccess {Array} address 配送地址,仅获取自己信息时出现
        @apiSuccessExample {json} Success Response:
        {
            "uid": 1,
            "avatar": "http://xxxx.com/avatar.png",
            "name": "001",
            // 以下为用户获取自己信息时才会出现
            "level": 0,
            "register_at": "2016-03-27 00:00:00",
            "phone": "99999",
            "address": []
        }

        @apiError UserNotExists 用户不存在
        """
        uid = int(uid)
        # hack: 因为改url涉及面太广,所以通过查看self.require_shop 来判定吧-。-
        shop = self.is_shop()

        user = User.get_instance_by_id(self.orm_session, uid)
        if user:
            result = self._get_user_info(user, shop)
            self.write(result)
        else:
            self.write(dict(
                status=1,
                msg="no such user",
            ))
示例#3
0
        def wrapper(obj, uid):
            uid = int(uid)
            user = User.get_instance_by_id(obj.orm_session, uid)

            obj.seller = user
            if user.level == level:
                return func(obj, uid)
            else:
                obj.write(dict(
                    status=1,
                    msg="user level error",
                ))
                return
示例#4
0
    def wrapper(obj, uid):
            uid = int(uid)
            user = User.get_instance_by_id(obj.orm_session, uid)
            _uid = obj.get_current_user()

            if user.id == _uid or obj.is_admin:
                obj._uid= _uid
                return func(obj, uid)
            else:
                obj.write(dict(
                    status=1,
                    msg="please login"
                ))
                return
示例#5
0
    def put(self, uid):
        """
        @apiDescription 修改用户信息
        @api {put} /user/([0-9]+)/? 修改用户信息
        @api {put} /shop/([0-9]+)/? 修改商家信息
        @apiGroup user
        @apiGroup shop

        @apiParam {Number} [uid] uid
        @apiParam {Number} [level] 级别
        @apiParam {String} [passwd] 密码
        @apiParam {String} [phone] 手机号
        @apiParam {String} [name] 名字
        @apiParam {String} [address] 地址

        @apiPermission user

        @apiError UserNotExists 用户不存在
        """
        to_change = dict(
            avatar=self.get_argument("avatar", None),
            level=int(self.get_argument("level", 0)),
            passwd=self.get_argument("passwd", None),
            phone=self.get_argument("phone", None),
            name=self.get_argument("name", None),
            address=self.get_argument("addresses", None)
        )

        user = User.get_instance_by_id(self.orm_session, uid)
        if not user:
            self.write(dict(
                status=1,
                msg="user does not exists"
            ))
            return

        for key, value in to_change.items():
            if value:
                setattr(user, key, value)
        self.orm_session.commit()
        self.write({})
示例#6
0
    def delete(self, uid):
        """
        @apiDescription 删除食品
        @api {delete} /shop/([0-9]+)/foods/? 删除
        @apiGroup food

        @apiParam {Number} fid 食品id

        @apiPermission seller
        """
        uid = int(uid)
        user = User.get_instance_by_id(self.orm_session, uid)
        fid = int(self.get_argument("fid"))
        if not user:
            self.write(dict(
                status=1,
                msg="user not exist",
            ))
            return

        Food.delete(self.orm_session, user.id, fid)
        self.write({})