コード例 #1
0
def make_sid(user_type, uid, device_type, cuid):
    """
    生成一个新的sid,使用场景:注册、登录

    :param user_type:
    :param uid:
    :param device_type:
    :param cuid:
    :return:
    """

    # 生成新的sid_info
    new_sid_info = sid_info.SidInfo(user_type=user_type,
                                    userid=uid,
                                    version=config.APP_BACKEND_VERSION,
                                    timestamp=int(time.time()),
                                    device_type=device_type,
                                    cuid=cuid
                                    )

    # 生成新的sid
    new_sid = sid_manager.SidManager.info2sid(new_sid_info)

    # 更新用户表的sid
    UserDao.update({
        "id": uid,
        "sid": new_sid
    })

    return new_sid
コード例 #2
0
    def _process_imp(self):

        # 不存在该用户
        user = UserDao.get_by_phone(self.para_map["phone"])
        if not user:
            self.ret_code = errcode.USER_NOT_EXIST
            self.ret_msg = 'phone is not exist'
            return

        # 检查短信验证码
        sms = SmsDao.get_by_phone_and_code(self.para_map["phone"],
                                           self.para_map["code"])
        if not sms:
            self.ret_code = errcode.SEND_SMS_ERROR
            self.ret_msg = 'code is error'
            return

        phone = self.para_map["phone"]
        cuid = self.common_param["cuid"]
        device_type = self.common_param["device_type"]
        device_os = self.common_param["device_os"]
        app_version = self.common_param["app_version"]
        channel = self.common_param["channel"]

        # 刷新DB的设备信息
        UserDao.update(
            {
                "phone": phone,
                "cuid": cuid,
                "device_type": device_type,
                "device_os": device_os,
                "app_version": app_version,
                "channel": channel
            },
            where_col="phone",
            where_col_str=True)

        # 生成新的sid
        new_sid = app_token_util.make_sid(user["source"], user["id"],
                                          device_type, cuid)

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {
            "user": user,
            "sid": new_sid,
        }

        return
コード例 #3
0
    def _process_imp(self):
        profile_dic = {
            "id": self.para_map["uid"],
            "sex": self.para_map["sex"],
            "avatar": self.para_map["avatar"],
            "user_name": self.para_map["user_name"],
        }

        UserDao.update(profile_dic)

        user = UserDao.get_by_id(self.para_map["uid"])

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"user": user}
        return
コード例 #4
0
    def _process_imp(self):
        user = UserDao.get_by_id(self.uid)
        if user["source"] != constant.USER_SOURCE_DOCTOR:
            self.ret_code = errcode.USER_NOT_DOCTOR
            self.ret_msg = 'user not doctor'
            return

        # 插入帖子
        news_id = NewsDao.insert({
            "author_id": self.uid,
            "title": self.para_map["title"],
            "content": self.para_map["content"],
        })

        # 插入帖子的图片
        for img_url in self.para_map["img_urls"]:
            NewsImgDao.insert({"news_id": news_id, "img_url": img_url})

        # 插入帖子和news的映射
        NewsCategoryMapDao.insert({
            "news_id": news_id,
            "category_id": self.para_map["category_id"]
        })

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"news_id": news_id}
        return
コード例 #5
0
    def _process_imp(self):
        answer_list = AskAnswerDao.get_by_page(self.para_map["ask_id"],
                                               self.para_map["page_num"],
                                               self.para_map["page_size"])

        for answer in answer_list:
            # 回答用户
            user = UserDao.get_by_id(answer["user_id"])
            answer["user"] = user

            # 回答的图片
            ask_imgs = AskAnswerImgDao.get_by_answer(answer["id"])
            answer["imgs"] = ask_imgs

            # 该用户是否对这些回答点过赞
            if AskAnswerLikeDao.get_by_answer_user(answer["id"],
                                                   answer["user_id"]):
                answer["is_like"] = 1
            else:
                answer["is_like"] = 0

            # 美化返回值
            answer["answer_id"] = answer["id"]
            del answer["id"]

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"answer_list": answer_list}
        return
コード例 #6
0
    def _process_imp(self):

        # 手机号已经存在
        user = UserDao.get_by_phone(self.para_map["phone"])
        if user:
            self.ret_code = errcode.USER_ALREADY_EXIST
            self.ret_msg = 'phone is already exist'
            return

        # 检查短信验证码
        sms = SmsDao.get_by_phone_and_code(self.para_map["phone"],
                                           self.para_map["code"])
        if not sms:
            self.ret_code = errcode.SEND_SMS_ERROR
            self.ret_msg = 'code is error'
            return

        phone = self.para_map["phone"]
        cuid = self.common_param["cuid"]
        device_type = self.common_param["device_type"]
        device_os = self.common_param["device_os"]
        app_version = self.common_param["app_version"]
        channel = self.common_param["channel"]

        user_id = UserDao.insert({
            "phone": phone,
            "cuid": cuid,
            "device_type": device_type,
            "device_os": device_os,
            "app_version": app_version,
            "channel": channel
        })
        user = UserDao.get_by_id(user_id)

        # 生成新的sid,初次注册默认是用户,要上传资料审核才能成为医生
        new_sid = app_token_util.make_sid(constant.USER_SOURCE_LOGIN_USER,
                                          user_id, device_type, cuid)

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {
            "user": user,
            "sid": new_sid,
        }

        return
コード例 #7
0
    def _process_imp(self):
        # 已经有用户使用该手机,不能被绑定
        user = UserDao.get_by_phone(self.para_map["phone"])
        if user:
            self.ret_code = errcode.USER_ALREADY_EXIST
            self.ret_msg = 'phone is already exist'
            return

        # 检查短信验证码
        sms = SmsDao.get_by_phone_and_code(self.para_map["phone"], self.para_map["code"])
        if not sms:
            self.ret_code = errcode.SEND_SMS_ERROR
            self.ret_msg = 'code is error'
            return

        phone = self.para_map["phone"]
        uid = self.para_map["uid"]
        cuid = self.common_param["cuid"]
        device_type = self.common_param["device_type"]

        UserDao.update({
            "phone": phone,
            "id": uid,
        }
        )
        user_info = UserDao.get_profile_by_phone(phone)

        # 生成新的sid
        new_sid = app_token_util.make_sid(user["source"], uid, device_type, cuid)

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {
            "user": user_info,
            "sid": new_sid,
        }

        return
コード例 #8
0
    def _process_imp(self):
        asks = AskDao.get_by_page(self.para_map["page_num"],
                                  self.para_map["page_size"])

        for ask in asks:
            # 获取问题的提问用户
            user = UserDao.get_by_id(ask["user_id"])
            ask["user"] = user

            # 获取问题的图片
            ask_imgs = AskImgDao.get_by_askid(ask["id"])
            ask["imgs"] = ask_imgs

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = asks

        return
コード例 #9
0
    def _process_imp(self):
        # 用户必须存在
        user = UserDao.get_by_phone(self.para_map["phone"])
        if not user:
            self.ret_code = errcode.SEND_SMS_ERROR
            self.ret_msg = 'user not exist'
            return

        # 保存到数据库
        code = random.randint(1000, 9999)
        SmsDao.insert(self.para_map["phone"], code, constant.SMS_FORGET_PASS)

        # 发送短信
        send_sms_task.send_forget_pass_sms.delay(self.para_map["phone"], code)

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'

        return
コード例 #10
0
    def _process_imp(self):
        news = NewsDao.get_by_category(self.para_map["category_id"],
                                       self.para_map["page_num"],
                                       self.para_map["page_size"])

        for new in news:
            # 图片
            imgs = NewsImgDao.get_by_news_id(new["id"])
            new["imgs"] = imgs

            # 作者
            author = UserDao.get_by_id(new["author_id"])
            logger.error("author= %s" % author)
            new["author"] = author if author else {}
            del new["author_id"]

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"news": news}
        return
コード例 #11
0
    def _process_imp(self):
        user = UserDao.get_by_id(self.uid)
        if user["source"] != constant.USER_SOURCE_DOCTOR:
            self.ret_code = errcode.USER_NOT_DOCTOR
            self.ret_msg = 'user not doctor'
            return

        # 插入问题
        ask_id = AskDao.insert({
            "author_id": self.uid,
            "user_type": constant.USER_SOURCE_DOCTOR,
            "title": self.para_map["title"],
            "content": self.para_map["content"],
        })

        # 插入问题的图片
        for img_url in self.para_map["img_urls"]:
            AskImgDao.insert({"ask_id": ask_id, "img_url": img_url})

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"ask_id": ask_id}
        return
コード例 #12
0
    def _process_imp(self):
        user = UserDao.get_by_id(self.uid)
        if not user:
            logger.error("post ask user:%s not exist" % self.uid)
            self.ret_code = errcode.USER_NOT_EXIST
            self.ret_msg = 'user not exist'
            return

        # 插入问题
        ask_id = AskDao.insert({
            "author_id": self.uid,
            "user_type": self.user_type,
            "title": self.para_map["title"],
            "content": self.para_map["content"],
        })

        # 插入问题的图片
        for img_url in self.para_map["img_urls"]:
            AskImgDao.insert({"ask_id": ask_id, "img_url": img_url})

        self.ret_code = errcode.NO_ERROR
        self.ret_msg = 'ok'
        self.ret_data = {"ask_id": ask_id}
        return
コード例 #13
0
        # 检查sid是否解析正确
        sid_info = sid_manager.SidManager.sid2info(sid)
        if not sid_info:
            self.ret_code = errcode.SID_CANNOT_RESOLVE
            self.ret_msg = "sid cannot resolve to sid_info"
            logger.error("sid cannot resolve to sid_info: %s" % sid)
            return False

        # 如果是登录用户或者医生,则需要校验
        if sid_info.user_type in [
                constant.USER_SOURCE_LOGIN_USER, constant.USER_SOURCE_DOCTOR
        ]:
            # 检查sid在db(也可以是redis中)中是否和用户匹配
            # todo: 优化为从redis中获取
            ret = UserDao.check_sid(sid_info.userid, sid)
            if not ret:
                self.ret_code = errcode.SID_NOT_CORRECT
                self.ret_msg = "sid not correct"
                logger.error("uid:%s, sid:%s is not correct!!!" %
                             (sid_info.userid, sid))
                return False

        self.uid = sid_info.userid  # 这个是医生、用户的id,可能是游客id
        self.user_type = sid_info.user_type  # 这个是用户类型,0-游客,1-用户,2-医生
        return True

    def _parse_and_check_parameters(self):
        """
        1、解析参数 -> self.para_map中。
        2、检验参数是否正确?是否必传的参数没有传?