(username: str, type: str = "chat", access_token: str = "")
| 285 | |
| 286 | @staticmethod |
| 287 | def chat_generate(username: str, type: str = "chat", access_token: str = ""): |
| 288 | application_access_token = ApplicationAccessToken.objects.filter(access_token=access_token).first() |
| 289 | |
| 290 | if not application_access_token: |
| 291 | raise AppApiException(1005, _("Invalid access token")) |
| 292 | |
| 293 | auth_setting = application_access_token.authentication_value |
| 294 | max_attempts = auth_setting.get("max_attempts", 1) |
| 295 | |
| 296 | need_captcha = True |
| 297 | if max_attempts == -1: |
| 298 | need_captcha = False |
| 299 | elif max_attempts > 0: |
| 300 | fail_count = cache.get(system_get_key(f"{type}_{username}"), version=system_version) or 0 |
| 301 | need_captcha = fail_count >= max_attempts |
| 302 | |
| 303 | return CaptchaSerializer._generate_captcha_if_needed(username, type, need_captcha) |
| 304 | |
| 305 | @staticmethod |
| 306 | def _generate_captcha_if_needed(username: str, type: str, need_captcha: bool): |
no test coverage detected