示例#1
0
    def reset_password(self, cellphone_number, password, code, country_code, cellphone_dict=dict(), base_url=None):
        country_code_obj = self.user.get_country_code(country_code)
        if country_code_obj:
            user = self.user.user.get_by_country_code_and_cellphone(country_code_obj.id, cellphone_number)
            if user:
                cellphone_number_check = country_code + cellphone_number
                if self.user.check_threemonth_isvalid(user):
                    if Code.check_code(cellphone_number_check, code):
                        result = self.user.reset_password(cellphone_number, password, country_code)
                        if Result.is_success(result):
                            if not self.bind_cellphone(cellphone_dict, user.id):
                                return Result.result_failed("bind cellphone failed")
                            self.user.set_username(user.username)
                            if not Result.is_success(self.user.add_token()):
                                result = Result.result_failed("login failed!")
                            else:
                                information = self.user.get_user_information(user.id, base_url)
                                result["data"] = information
                        else:
                            result = Result.result_failed("change password failed!")
                    else:
                        result = Result.result_failed("verification code is incorrect!")
                else:
                    result = Result.result_update_beyond_three_month()
            else:
                result = Result.result_failed("user not exist!")
        else:
            result = Result.result_failed("country_code not exist")

        return result
    def authenticate(self, country_code, username, password, cellphone_dict,
                     base_url, code):
        country_code_object = self.user.get_country_code(country_code)
        country_code_id = country_code_object.id if country_code_object else 0

        OHHOLog.print_log("check user")
        user_check_result = self.user.check_user_only_by_user(
            username, code, country_code_id)
        OHHOLog.print_log(user_check_result)
        user = self.user.get_by_cellphone(username)
        cellphone_key = cellphone_dict.get("key", None)
        self.cellphone.set_key(cellphone_key)
        cellphone = self.cellphone.get()

        OHHOLog.print_log("check user and cellphone relation")
        if user and cellphone:
            is_bind = self.cellphone.is_bound_by_user(cellphone.id, user.id)
            if is_bind:
                cellphone_relation_result = Result.result_success()
            else:
                OHHOLog.print_log("unsafe cellphone!")
                cellphone_relation_result = Result.result_failed()
        else:
            OHHOLog.print_log("user or cellphone not exist!")
            cellphone_relation_result = Result.result_failed()

            if not cellphone:
                OHHOLog.print_log("add cellphone!")
                success = self.cellphone.add_cellphone(cellphone_dict)
                if success:
                    add_cellphone_result = Result.result_success()
                else:
                    add_cellphone_result = Result.result_failed()
                OHHOLog.print_log(add_cellphone_result)
        OHHOLog.print_log(cellphone_relation_result)

        if Result.is_success(user_check_result) and Result.is_success(
                cellphone_relation_result):
            result = Result.result_success()
        elif Result.is_password_incorrect(
                user_check_result) or Result.is_update_beyond_three_month(
                    user_check_result):
            result = user_check_result
        elif Result.is_success(user_check_result):
            result = Result.result_unsafe()
        elif Result.is_not_exist(user_check_result):
            result = Result.result_not_exist()
        else:
            result = Result.result_failed()
        if user and Result.is_success(result):
            result["data"] = self.user.get_user_information(user.id, base_url)

        return result
示例#3
0
    def bind_cellphone(self, cellphone_dict, user_id):
        OHHOLog.print_log(cellphone_dict)
        OHHOLog.print_log(user_id)
        if cellphone_dict and cellphone_dict.get("key", ""):
            key = cellphone_dict.get("key")
            OHHOLog.print_log(key)
            self.cellphone.set_key(key)
            cellphone_object = self.cellphone.get()
            if not cellphone_object:
                OHHOLog.print_log("no cellphone object")
                self.cellphone.add_cellphone(cellphone_dict)
                cellphone_object = self.cellphone.get()

            if cellphone_object:
                OHHOLog.print_log("no cellphone object at all")
                if not self.cellphone.is_bound_by_user(cellphone_object.id, user_id):
                    OHHOLog.print_log("begin to bind user")
                    success = self.cellphone.bind_cellphone(cellphone_object.id, user_id)
                    OHHOLog.print_log(success)
                    return Result.is_success(success)
                else:
                    return True
            else:
                return False
        else:
            return True
示例#4
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="注册不成功")