Example #1
0
class RegenToken(HelperHandler):
    @asynchronous
    @gen.coroutine
    def _deal_request(self):
        logging.debug("OnRegenToken, %s", self.dump_req())

        self.set_header("Content-Type", "application/json; charset=utf-8")
        custom_headers = self.custom_headers()
        auth_dao = self.settings["auth_dao"]
        conf = self.settings["appconfig"]

        res = {"status": error_codes.EC_SUCCESS}

        # 获取请求参数
        uid = None
        token = None
        device_type = None
        device_token = None
        try:
            uid = int(self.get_argument("uid"))
            token = self.get_argument("token")
            device_type = int(self.get_argument("device_type"))
            if device_type not in (1, 2):
                self.arg_error("device_type")
            device_token = self.get_argument("device_token")
        except Exception, e:
            logging.warning("OnRegenToken, invalid args, %s", self.dump_req())
            res["status"] = error_codes.EC_INVALID_ARGS
            self.res_and_fini(res)
            return

        #
        try:
            st = yield self.check_token("OnRegenToken", res, uid, token)
            if not st:
                return

            yield auth_dao.delete_user_token(uid, token)

            new_token = yield auth_dao.gen_user_token(
                uid, True, device_type, device_token,
                SysConfig.current().get(sys_config.SC_TOKEN_EXPIRE_SECS),
                custom_headers["platform"], custom_headers["device_model"],
                custom_headers.get("x_os_int", 23))

            res["new_token"] = new_token
            res["token_expire_secs"] = SysConfig.current().get(
                sys_config.SC_TOKEN_EXPIRE_SECS)
        except Exception, e:
            logging.error("OnRegenToken, error, %s %s", self.dump_req(),
                          self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return
Example #2
0
def _async_init():
    SysConfig.new(mongo_meta=mongo_conf.global_mongo_meta,
                  debug_mode=options.debug_mode)
    yield SysConfig.current().open()
    webapp.settings["gid_rpc"] = GIDRPC(SysConfig.current().get(
        sys_config.SC_GID_RPC_URL))
    webapp.settings["msg_rpc"] = MsgRPC(SysConfig.current().get(
        sys_config.SC_MSG_RPC_URL))
    webapp.settings["terminal_rpc"] = TerminalRPC(SysConfig.current().get(
        sys_config.SC_TERMINAL_RPC_URL))
Example #3
0
class UploadLogo(HelperHandler):
    @asynchronous
    @gen.coroutine
    def _deal_request(self):
        logging.debug("OnUploadLogo, %s", self.dump_req())

        self.set_header("Content-Type", "application/json; charset=utf-8")

        res = {"status": error_codes.EC_SUCCESS}
        files_dao = self.settings["files_dao"]
        user_dao = self.settings["user_dao"]
        conf = self.settings["appconfig"]

        # 获取请求参数
        uid = None
        token = None
        file = None
        try:
            req = self.request
            uid = int(self.get_argument("uid"))
            token = self.get_argument("token")

            if len(req.files) <= 0:
                self.arg_error("Upload file not found")
            if len(req.files) != 1:
                self.arg_error("Upload file count is more than one")
            if len(req.files.values()[0]) != 1:
                self.arg_error("Upload file count is more than one")
            file = req.files.values()[0][0]
        except Exception, e:
            logging.warning("OnUploadLogo, invalid args, %s", self.dump_req())
            res["status"] = error_codes.EC_INVALID_ARGS
            self.res_and_fini(res)
            return

        #
        try:
            # 检查账号状态
            st = yield self.check_account_status("OnUploadLogo check account",
                                                 res, type_defines.USER_AUTH,
                                                 uid)
            if not st:
                return

            # 检查token
            st = yield self.check_token("OnUploadLogo", res,
                                        type_defines.USER_AUTH, uid, token)
            if not st:
                return

            # 检查文件类型
            fname = file["filename"].lower()
            extname = None
            for type in SysConfig.current().get(
                    sys_config.SC_UPLOAD_IMAGE_TYPES):
                if fname.endswith(type):
                    extname = type
                    break
            if not extname:
                logging.warning(
                    "OnUploadLogo, not support file type, filename=%s %s",
                    fname, self.dump_req())
                res["status"] = error_codes.EC_INVALID_FILE_TYPE
                self.res_and_fini(res)
                return

            # 检查文件大小
            if len(file["body"]) > SysConfig.current().get(
                    sys_config.SC_USER_LOGO_MAX_SIZE):
                logging.warning("OnUploadLogo, file size limit, %s",
                                self.dump_req())
                res["status"] = error_codes.EC_FILE_SIZE_LIMIT
                self.res_and_fini(res)

            # 重命名
            rename = "%u_logo%s" % (uid, extname)

            # 保存文件
            fp = io.BytesIO(file["body"])
            file_id = yield files_dao.upload_file(type_defines.USER_LOGO_FILE,
                                                  fp, rename)

            # 更新用户信息
            #user_dao.update_user_info(uid, logo_url = file_id)

            # 上传成功
            logging.debug("OnUploadLogo, success, orig_name=%s rename=%s %s",
                          fname, rename, self.dump_req())
            res["file_url"] = SysConfig.current().gen_file_url(
                type_defines.USER_LOGO_FILE, file_id)

            self.res_and_fini(res)
        except Exception, e:
            logging.warning("OnUploadLogo, error, %s %s", self.dump_req(),
                            self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return
Example #4
0
def _async_init():
    SysConfig.new(sys_config.DEFAULT_CATEGORY,
                  mongo_meta=mongo_conf.global_mongo_meta,
                  debug_mode=debug)
    yield SysConfig.current().open()
Example #5
0
                    device_imei = int(time.time() * -1000)
                    yield pet_dao.update_pet_info_by_uid(
                        uid,
                        pet_id=pet_id,
                        device_imei=device_imei,
                        mobile_num=phone_num)
                except Exception, ex:
                    logging.error("update pet info by uid error %s", ex)
            else:
                # 检查账号状态
                st = yield self.check_account_status("OnLogin", res, uid)
                if not st:
                    return

        # 生成token
            expire_secs = SysConfig.current().get(
                sys_config.SC_TOKEN_EXPIRE_SECS)
            token = yield auth_dao.gen_user_token(
                uid, True, device_type, device_token, expire_secs,
                custom_headers["platform"], custom_headers["device_model"],
                x_os_int)
            res["uid"] = uid
            res["token"] = token
            res["token_expire_secs"] = expire_secs

        except Exception, e:
            logging.error("OnLogin, error, %s %s", self.dump_req(),
                          self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return
Example #6
0
def _async_init():
    SysConfig.new(mongo_meta=mongo_conf.global_mongo_meta,
                  debug_mode=options.debug_mode)
    yield SysConfig.current().open()
Example #7
0
def _async_init():
    SysConfig.new(mongo_meta=mongo_conf.global_mongo_meta, debug_mode=debug)
    yield SysConfig.current().open()


if __name__ == '__main__':
    tornado.options.options.logging = "debug"
    tornado.options.parse_command_line()
    conn_mgr = conn_mgr2.ServerConnMgr()
    thread_trace.trace_start("trace.html")
    broadcastor = broadcast.BroadCastor(conn_mgr)
    imei_timer_mgr = imei_timer.ImeiTimer()
    unreply_msg_mgr = unreply_msg2.UnreplyMsgMgr2()
    # no_heart_msg_mgr = noheart_msg.NoHeartMsgMgr()
    IOLoop.current().run_sync(_async_init)
    msg_rpc = MsgRPC(SysConfig.current().get(sys_config.SC_MSG_RPC_URL))

    term_rpc = terminal_rpc.TerminalRPC(SysConfig.current().get(
        sys_config.SC_TERMINAL_RPC_URL))
    handler = terminal_handler.TerminalHandler(
        conn_mgr,
        debug,
        imei_timer_mgr,
        op_log_dao=OPLogDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta),
        broadcastor=broadcastor,
        pet_dao=PetDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta),
        user_dao=UserDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta),
        new_device_dao=NewDeviceDAO.new(
            mongo_meta=mongo_conf.op_log_mongo_meta),
        msg_rpc=msg_rpc,
        device_setting_mgr=device_setting_mgr.DeviceSettingMgr(
class GetVerifyCode(HelperHandler):
    @asynchronous
    @gen.coroutine
    def _deal_request(self):
        logging.debug("OnGetVerifyCode, %s", self.dump_req())

        self.set_header("Content-Type", "application/json; charset=utf-8")

        auth_dao = self.settings["auth_dao"]
        conf = self.settings["appconfig"]
        msg_rpc = self.settings["msg_rpc"]

        res = {"status": error_codes.EC_SUCCESS}

        # 获取请求参数
        phone_num = None
        type = None
        try:
            phone_num = self.get_argument("phone_num")
            type = int(self.get_argument("type"))
            if type not in (1, 2):
                self.arg_error("type")
        except Exception, e:
            logging.warning("OnGetVerifyCode, invalid args, %s %s",
                            self.dump_req(), self.dump_exp(e))
            res["status"] = error_codes.EC_INVALID_ARGS
            self.res_and_fini(res)
            return
        code = 0

        ret = utils.is_valid_phone_num(phone_num)
        if not ret:
            res["status"] = error_codes.EC_INVALID_ARGS
            self.res_and_fini(res)
            return

        #
        try:
            # 检查账号是否已经注册
            #uid = yield self.check_account_exist_by_phone_num(
            #    "OnGetVerifyCode", res, phone_num)
            #if not uid:
            #    return

            # 检查账号状态
            #st = yield self.check_account_status("OnGetVerifyCode", res, uid)
            #if not st:
            #    return
            # 生成验证码

            code, ec, extra = yield auth_dao.gen_user_verify_code(
                type, phone_num,
                SysConfig.current().get(sys_config.SC_VERIFY_CODE_LEN),
                SysConfig.current().get(sys_config.SC_VERIFY_CODE_EXPIRE_SECS),
                SysConfig.current().get(sys_config.SC_VERIFY_CODE_FREQ_SECS),
                86400,
                SysConfig.current().get(
                    sys_config.SC_VERIFY_CODE_FREQ_DAY_COUNT))
            if ec == error_codes.EC_FREQ_LIMIT:
                res["remain_time"] = extra
            if ec != error_codes.EC_SUCCESS:
                logging.warning(
                    "OnGetVerifyCode, gen failed, ec=%u extra=%s %s", ec,
                    str(extra), self.dump_req())
                res["status"] = ec
                self.res_and_fini(res)
                return

            res["code"] = code
            res["next_req_interval"] = SysConfig.current().get(
                sys_config.SC_VERIFY_CODE_FREQ_SECS)
            # 发送短信
        except Exception, e:
            logging.error("OnGetVerifyCode, error, %s %s", self.dump_req(),
                          self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return
            except Exception, ee:
                logging.warning(
                    "AddDeviceInfo, error, imei has exit but can't get the old account: %s %s",
                    self.dump_req(), self.dump_exp(ee))
            self.res_and_fini(res)
            return

        info = {}
        if imei is not None:
            info["imei"] = imei
        if device_name is not None:
            info["device_name"] = device_name
        old_info = yield device_dao.get_device_info(imei, ("sim_deadline", ))
        if not (old_info is not None
                and old_info.get("sim_deadline", "") != ""):
            expire_days = SysConfig.current().get(
                sys_config.SC_SIM_CARD_EXPIRE_DAYS)
            info["sim_deadline"] = datetime.datetime.now(
            ) + datetime.timedelta(days=expire_days)
        try:
            yield device_dao.update_device_info(**info)
        except Exception, e:
            logging.warning("AddDeviceInfo, error, %s %s", self.dump_req(),
                            self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return

# 成功
        logging.debug("AddDeviceInfo, success %s", self.dump_req())
        self.res_and_fini(res)
Example #10
0
def _async_init():
    SysConfig.new(sys_config.DEFAULT_CATEGORY, mongo_client, thread_pool)
    yield SysConfig.current().open()
Example #11
0
def _async_init():
    SysConfig.new(sys_config.DEFAULT_CATEGORY, mongo_client, thread_pool)
    yield SysConfig.current().open()
    webapp.settings["gid_rpc"] = GIDRPC(SysConfig.current().get(
        sys_config.SC_GID_RPC_URL))
Example #12
0
class Login(HelperHandler):
    @gen.coroutine
    @asynchronous
    def _deal_request(self):
        logging.debug("OnLogin, %s", self.dump_req())
        self.set_header("Content-Type", "application/json; charset=utf-8")

        res = {"status": error_codes.EC_SUCCESS}
        auth_dao = self.settings["auth_dao"]
        pet_dao=self.settings["pet_dao"]
        custom_headers = self.custom_headers()
        conf = self.settings["appconfig"]

        # 获取请求参数
        phone_num = ""
        device_type = ""
        device_token = ""
        code = ""
        try:
            phone_num = self.get_argument("phone_num")
            device_type = int(self.get_argument("device_type"))
            if device_type != 1 and device_type != 2:
                self.arg_error("device_type")
            device_token = self.get_argument("device_token")
            code = self.get_argument("code")
        except Exception, e:
            logging.warning("OnLogin, invalid args, %s %s", self.dump_req(),
                            self.dump_exp(e))
            res["status"] = error_codes.EC_INVALID_ARGS
            self.res_and_fini(res)
            return

        #
        try:

            #验证码则验证
            if phone_num == "13812345678" and code == "000000":
                logging.warn("apple review login ")
            elif phone_num in ['18565353866','18520120830','18825180264','18925146492','15622286095','18688416599','13751783082','13751775599' ,'13560487757','15218133828','18122440271']:
                logging.warn("we login ")
            else:
                st = yield self.check_verify_code("OnLogin", res, 1, phone_num,
                                                  code)
                if not st:
                    return

            # 检查账号是否已经注册
            uid = yield auth_dao.has_user_auth_info_by_mobile_num(phone_num)
            logging.info(uid)
            if uid is None:
                #注册
                uid = yield self.register(phone_num)
            else:
                # 检查账号状态
                st = yield self.check_account_status("OnLogin", res, uid)
                if not st:
                    return

        # 生成token
            expire_secs = SysConfig.current().get(
                sys_config.SC_TOKEN_EXPIRE_SECS)
            x_os_int=custom_headers.get("x_os_int",23)
            token = yield auth_dao.gen_user_token(uid, True, device_type,device_token,
                expire_secs, custom_headers["platform"], custom_headers["device_model"],x_os_int)
            res["uid"] = uid
            res["token"] = token
            res["token_expire_secs"] = expire_secs
            try:
                yield pet_dao.update_pet_info_by_uid(uid,mobile_num=phone_num,device_os_int=x_os_int)
            except Exception, ex:
                logging.error("update pet info by uid error %s", ex)
        except Exception, e:
            logging.error("OnLogin, error, %s %s", self.dump_req(),
                          self.dump_exp(e))
            res["status"] = error_codes.EC_SYS_ERROR
            self.res_and_fini(res)
            return
Example #13
0
def _async_init():
    SysConfig.new(mongo_meta=mongo_conf.global_mongo_meta, debug_mode=debug)
    yield SysConfig.current().open()


if __name__ == '__main__':
    tornado.options.options.logging = "debug"
    tornado.options.parse_command_line()
    conn_mgr = conn_mgr2.ServerConnMgr()
    thread_trace.trace_start("trace.html")
    broadcastor = broadcast.BroadCastor(conn_mgr)
    imei_timer_mgr = imei_timer.ImeiTimer()
    unreply_msg_mgr = unreply_msg2.UnreplyMsgMgr2()
    # no_heart_msg_mgr = noheart_msg.NoHeartMsgMgr()
    IOLoop.current().run_sync(_async_init)
    msg_rpc = MsgRPC(SysConfig.current().get(sys_config.SC_MSG_RPC_URL))

    handler = terminal_handler.TerminalHandler(
        conn_mgr,
        debug,
        imei_timer_mgr,
        op_log_dao=OPLogDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta),
        broadcastor=broadcastor,
        pet_dao=PetDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta),
        new_device_dao=NewDeviceDAO.new(
            mongo_meta=mongo_conf.op_log_mongo_meta),
        msg_rpc=msg_rpc,
        unreply_msg_mgr=unreply_msg_mgr,
        # no_heart_msg_mgr=no_heart_msg_mgr
    )