Пример #1
0
    def post(self):
        user = User()
        the_post = Post()
        country_code = the_post.get_country_code(self)
        cellphone = the_post.get_username(self)
        password = the_post.get_password(self)
        code = the_post.get_code(self)
        instance = LogicBackstageRegister()
        register_instance = LogicRegister()
        msg = ""
        country_code_object = user.get_country_code(country_code)
        if country_code_object and not user.get_by_country_code_and_cellphone(
                country_code_object.id, cellphone):
            register_result = register_instance.add_new_user(
                password, cellphone, country_code)
            OHHOLog.print_log(register_result)
            if Result.is_success(register_result):
                user_id = register_result.get("user_id", 0)

                user_object = user.get_by_id(user_id)
                if user_object:
                    self.set_secure_cookie("username", user_object.username)
                    return self.redirect("/backstage/home/")
        # if Code.check_code(username, code):  # 目前验证码没有用,先注释掉
        #     pass
        # else:
        #     return self.render(BACKSTAGE_REGISTER_HTML,
        #                        postUrl=BACKSTAGE_REGISTER_URL,
        #                        msg="验证码不正确"
        #                        )
        # if username and password:
        #     result1 = instance.register(username, password)
        #     if result1:
        #         self.set_secure_cookie("username", username)
        #         return self.redirect("/backstage/home/")
        return self.render(BACKSTAGE_REGISTER_HTML,
                           postUrl=BACKSTAGE_REGISTER_URL,
                           msg="注册不成功")
class LogicCellphoneUnbindDevice(object):
    def __init__(self):
        self.user = User()
        self.device = Device()
        self.imei = IMEI()

    def unbind_device(self, cellphone, code, identity, mac_address,
                      country_code):
        # OHHOLog.print_log(cellphone)
        # OHHOLog.print_log(identity)
        # OHHOLog.print_log(mac_address)
        if country_code and cellphone:
            the_cellphone = country_code + cellphone
        else:
            return Result.result_parameters_are_invalid(
                "country_code or cellphone is empty!")
        success = Code.check_code(the_cellphone, code)
        if success:
            country_code_object = self.user.get_country_code(country_code)
            country_code_id = country_code_object.id if country_code_object else 0
            user = self.user.get_by_country_code_and_cellphone(
                country_code_id, cellphone)
            if user:
                self.device.set_mac_address(mac_address)
                self.device.set_identity(identity)
                device = self.device.get_by_identity()
                if device:
                    # OHHOLog.print_log("before delete imei")
                    self.imei.delete_by_user_and_device(user.id, device.id)
                    # OHHOLog.print_log("after delete imei")
                    # query = self.imei.get_by_user_and_device(user.id, device.id)
                    # self.imei.delete_some(query)
                return self.device.unbind_device(user.id)
            else:
                return Result.result_not_exist(USER_NOT_EXIST)
        else:
            return Result.result_failed(PASSWORD_IS_INCORRECT)
class LogicRebindCellphone(object):
    def __init__(self):
        self.user = User()
        self.cellphone = Cellphone()

    def rebind_cellphone(self, cellphone_key, cellphone_number, code, base_url, cellphone_dict, country_code):
        the_cellphone = country_code + cellphone_number
        check = Code.check_code(the_cellphone, code)
        if check:
            country_code_object = self.user.country_code.get_by_country_code(country_code)
            country_code_id = country_code_object.id if country_code_object else 0
            # self.user.get_by_country_code_and_cellphone(country_code, cellphone_number)
            # user = self.user.get(cellphone_number)
            user = self.user.get_by_country_code_and_cellphone(country_code_id, cellphone_number)
            self.cellphone.set_key(cellphone_key)
            cellphone = self.cellphone.get()
            if not cellphone:
                success = self.cellphone.add_cellphone(cellphone_dict)
                if success:
                    cellphone = self.cellphone.get()
                else:
                    cellphone = None
            if cellphone:
                if not user:
                    OHHOLog.print_log(country_code)
                    OHHOLog.print_log(cellphone_number)
                    result = Result.result_failed("user doest not exist")
                else:
                    result = self.cellphone.bind_cellphone(cellphone.id, user.id)
                    data = self.user.get_user_information(user.id, base_url)
                    result["data"] = data
            else:
                result = Result.result_failed("cellphone does not exist!")
        else:
            result = Result.result_failed("code is incorrect!")
        return result