Beispiel #1
0
    def post(self):
        user_id = common.my_int(self.get_argument('user_id'))

        sex = common.my_int(self.get_argument('sex', None))
        height = common.my_int(self.get_argument('height', None))
        weight = common.my_int(self.get_argument('weight', None))
        nick = common.my_str(self.get_argument('nick', None))
        birthday = common.my_int(self.get_argument('birthday', None))
        blood_type = common.my_str(self.get_argument('blood_type', None))
        blood_pressure = common.my_str(self.get_argument('blood_pressure', None))
        heart_rate = common.my_int(self.get_argument('heart_rate', None))
        blood_sugar = common.my_int(self.get_argument('blood_sugar', None))

        args = dict(
            user_id=user_id,
            nick=common.text_filter(nick),
            sex=sex,
            height=height,
            weight=weight,
            birthday=birthday,
            blood_pressure=blood_pressure,
            blood_sugar=blood_sugar,
            blood_type=blood_type,
            heart_rate=heart_rate
        )
        self.user_handle.update_user_info(args)

        return self.finish(common.Ok())
Beispiel #2
0
    def post(self):
        """
        处理请求参数
        """
        phone = common.my_str(self.get_argument('phone'))
        app_package = common.my_str(self.get_argument('app_package'))
        verify_code = common.my_int(self.get_argument('verify_code'))
        is_right_phone = common.is_right_phone(phone)
        if not is_right_phone:
            return self.finish(err_conf.E_BAD_PHONE)
        sms_code = 0
        now = int(time.time())
        send_ts = 0
        sql = """select code, unix_timestamp(ts) as ts from phone_code_tickets64
        where phone={0} order by ts desc limit 1""".format(int(phone))
        result = self.db_handle.query(sql)
        for item in result:
            sms_code = item.code
            send_ts = item.ts
        if verify_code != sms_code:
            return self.finish(common.Err(err_conf.E_BAD_CHECK_PHONE_CODE))
        # 验证码5分钟内有效
        if now - send_ts > 5 * 60:
            return self.finish(common.Err(err_conf.E_PHONE_CODE_EXPIRE))

        # 生成token
        string_token = "{0}{1}{2}".format(phone, app_package, now)
        access_token = self.auth_handle.genarate_access_token(string_token)
        self.db_redis.set(access_token, phone, ex=5 * 60)
        response = {'code': 0, 'msg': 'ok', "access_token": access_token}
        return self.finish(response)
Beispiel #3
0
 def parse_request_body(self):
     """prepare for get body arguments"""
     try:
         request_arguments = self.request.arguments
         if request_arguments:
             new_request_arguments = {
                 k: common.my_str(v[0].decode('utf8'))
                 for k, v in request_arguments.items()
             }
             return new_request_arguments
         else:
             request_body = self.request.body
             request_data = request_body.decode('utf-8')
             request_data_dict = json.loads(request_data)
             self.request.arguments = {
                 k: [str(v)]
                 for k, v in request_data_dict.items()
             }
             new_request_arguments = {
                 k: common.my_str(v).decode('utf8')
                 for k, v in request_data_dict.items()
             }
             return new_request_arguments
     except Exception as e:
         raise tornado.web.HTTPError(status_code=400,
                                     log_message='bad_request')
Beispiel #4
0
 def post(self):
     """
     处理请求
     """
     user_id = common.my_int(self.get_argument('user_id'))
     phone = common.my_str(self.get_argument('phone'))
     access_token = common.my_str(self.get_argument('access_token'))
     user_phone = self.db_redis.get(access_token)
     if user_phone != phone:
         return self.finish(common.Err("无效的token或手机号!"))
     bind_user_id = self.auth_handle.get_user_id_by_phone(phone)
     if user_id != bind_user_id:
         return self.finish(common.Err("当前手机号已经绑定其他的微信/QQ账号!"))
     self.auth_handle.bind_phone(user_id, phone)
     return self.finish(common.Ok())
Beispiel #5
0
    def prepare(self):
        """
        请求前的操作
        """
        ret = self.check_must_have_param()
        if ret:
            return self.finish(ret)

        path = self.request.path
        user_id = common.my_int(self.get_argument('user_id', 0))
        # 校验登录态
        if path not in not_need_xyy:
            xyy = common.my_str(self.get_argument("xyy", ''))
            if not common.check_user_sid(user_id, xyy):
                return self.finish(common.Err(err_conf.E_BAD_XYY))

        request_data = self.parse_request_body()
        # 验证签名
        sign_info = check_sign.is_right_sign(path, request_data)
        reason = {}
        if isinstance(sign_info, tuple):
            sign_flag, reason = sign_info
        else:
            sign_flag = sign_info
        if not sign_flag:
            ret = common.Err(err_conf.ES_BAD_PARAM)
            error_code = reason.get('code', 0)
            if error_code == err_conf.E_BAD_SESSION:
                ret = common.Err(err_conf.E_BAD_SESSION)
            reason = json.dumps(reason, ensure_ascii=False, indent=4)
            ApiGraylog(request_data.get('user_id', 0), 'waterworld_bad_sign',
                       path, request_data.get('ver', ''), reason, self.request)
            self.finish(ret)
            return
Beispiel #6
0
 def post(self):
     user_id = common.my_int(self.get_argument('user_id'))
     xyy = common.my_str(self.get_argument("xyy"))
     if not common.check_user_sid(user_id, xyy):
         return self.finish(common.Err(err_conf.E_BAD_XYY))
     user_info = self.user_handle.get_user_info(user_id)
     response = dict(code=0, msg="ok", user_info=user_info)
     return self.finish(response)
Beispiel #7
0
 def get_user_session_key(self, user_id):
     """获取session key"""
     key = "session_key_{}".format(user_id)
     session_key = common.my_str(self.db_redis.get(key))
     if not session_key:
         session_key = self.genarate_session_key()
         self.db_redis.set(key, session_key, ex=7 * 86400)
     ttl = self.db_redis.ttl(key)
     return session_key, ttl
Beispiel #8
0
 def get_head_val(self, user_id):
     key = "wwd_head_val_{}".format(user_id)
     head_val = self.redis_handle.get(key)
     if head_val:
         return common.my_str(head_val)
     sql = """
     select head_val from user_info where user_id=:user_id
     """
     result = self.db_handle.query(sql, user_id=user_id)
     return result[0].head_val if result.first() else ''
Beispiel #9
0
 def post(self):
     '''
     处理请求
     '''
     phone = common.my_str(self.get_argument('phone'))
     is_right_phone = common.is_right_phone(phone)
     if not is_right_phone:
         return self.finish(common.Err(err_conf.E_BAD_PHONE))
     verify_code = random.randint(100000, 999999)
     params = []
     params.append(verify_code)
     sms_sign = "验证码"
     self.send_verify_code(self.template_id, params, phone, sms_sign)
     self.save_user_verify_code(phone, verify_code)
     response = common.Ok()
     return self.finish(response)
Beispiel #10
0
 def post(self):
     """
     请求
     """
     business_source = common.my_str(self.get_argument('business_source'))
     if business_source not in self.LEGEL_BUSINESS_SOURCE:
         return self.finish(common.Err(err_conf.E_BAD_BUSINESS_SOURCE))
     filename = qiniu_tools.get_random_filename()
     up_token = qiniu_tools.get_up_token(business_source, filename)
     response = {
         'code': 0,
         'msg': 'ok',
         'up_token': up_token,
         'filename': filename
     }
     self.finish(response)
Beispiel #11
0
    def run(self):
        """
        执行
        """
        job = self.beanstalk.reserve()
        data = json.loads(job.body)
        user_id = int(data['user_id'])
        if not user_id:
            return job.delete()
        if 'type' not in data.keys() or 'worktype' not in data.keys():
            return job.delete()
        raw_data = data['data']

        try:
            head_url = common.my_str(raw_data['head_url'])
            if head_url == "":
                return job.delete()

            imgdata = requests.get(head_url).content
            self.user_handle.upload_head_url(user_id, imgdata)
        except Exception:
            send_try_except()

        return job.delete()
Beispiel #12
0
    def post(self):
        """
        处理请求
        """
        code = common.my_str(self.get_argument('code'))
        response_info = self.auth_of_wechat(code)
        if not response_info:
            return self.finish(common.Err(err_conf.E_BAD_WX_AUTH))
        open_id = response_info['openid']
        access_token = response_info['access_token']
        refresh_token = response_info['refresh_token']
        response_info = self.query_user_info(open_id, access_token,
                                             refresh_token)
        if not response_info:
            return self.finish(common.Err(err_conf.E_BAD_WX_AUTH))
        union_id = response_info.get('unionid', '')
        head_url = response_info.get('headimgurl', '')
        nick = response_info.get('nickname', '')
        sex = response_info.get('sex', 0)  # 1是男性,2是女性,0是未知
        is_bind_phone = 0
        # 检查是否有user_id
        user_id = self.auth_handle.get_user_id_by_openid(open_id)
        data = {
            k: v[0].decode('utf-8')
            for k, v in self.request.arguments.items()
        }
        data.update({"sex": sex, "head_url": head_url, "nick": nick})
        if user_id > 0:
            phone = self.auth_handle.get_phone_by_user_id(user_id)
            is_bind_phone = 1 if phone else 0
            data.update({"user_id": user_id, "phone": phone})
            self.auth_handle.update_user_info(self.request, data)
        else:
            user_id = self.auth_handle.register_user(self.request, data)

        args = {
            "opend_id": open_id,
            "user_id": user_id,
            "source": self.get_argument("source", ""),
            "nick": nick,
            "sex": sex,
            "head_url": head_url,
            "status": 0,
            "union_id": union_id,
            "type": 2
        }
        self.auth_handle.save_wechat_openid_info(args)
        xyy = common.get_user_sid(user_id)
        session_key, ttl = self.auth_handle.get_user_session_key(user_id)
        response = {
            "code": 0,
            "msg": "ok",
            "session_key": session_key,
            "ttl": ttl,
            "is_bind_phone": is_bind_phone,
            "user_info": {
                "user_id": user_id,
                "nick": nick,
                "head_url": head_url,
                "xyy": xyy
            }
        }
        return self.finish(response)