执行 any-auto-register 风格注册流程。 返回 dict:包含 result(RegistrationResult 填充所需字段) + 额外上下文。
(self)
| 182 | return None |
| 183 | |
| 184 | def run(self): |
| 185 | """ |
| 186 | 执行 any-auto-register 风格注册流程。 |
| 187 | 返回 dict:包含 result(RegistrationResult 填充所需字段) + 额外上下文。 |
| 188 | """ |
| 189 | last_error = "" |
| 190 | settings = get_settings() |
| 191 | password_len = int(getattr(settings, "registration_default_password_length", DEFAULT_PASSWORD_LENGTH) or DEFAULT_PASSWORD_LENGTH) |
| 192 | |
| 193 | oauth_config = dict(self.extra_config or {}) |
| 194 | if not oauth_config: |
| 195 | oauth_config = { |
| 196 | "oauth_issuer": str(getattr(settings, "openai_auth_url", "") or "https://auth.openai.com"), |
| 197 | "oauth_client_id": str(getattr(settings, "openai_client_id", "") or "app_EMoamEEZ73f0CkXaXp7hrann"), |
| 198 | "oauth_redirect_uri": str(getattr(settings, "openai_redirect_uri", "") or "http://localhost:1455/auth/callback"), |
| 199 | } |
| 200 | |
| 201 | for attempt in range(self.max_retries): |
| 202 | try: |
| 203 | if attempt == 0: |
| 204 | self._log("=" * 60) |
| 205 | self._log("开始注册流程 V2 (Session 复用直取 AccessToken)") |
| 206 | self._log(f"请求模式: {self.browser_mode}") |
| 207 | self._log("=" * 60) |
| 208 | else: |
| 209 | self._log(f"整流程重试 {attempt + 1}/{self.max_retries} ...") |
| 210 | time.sleep(1) |
| 211 | |
| 212 | # 1. 创建邮箱 |
| 213 | self.email_info = self.email_service.create_email() |
| 214 | raw_email = str((self.email_info or {}).get("email") or "").strip() |
| 215 | if not raw_email: |
| 216 | last_error = "创建邮箱失败" |
| 217 | return {"success": False, "error_message": last_error} |
| 218 | |
| 219 | normalized_email = raw_email.lower() |
| 220 | self.inbox_email = raw_email |
| 221 | self.email = normalized_email |
| 222 | try: |
| 223 | self.email_info["email"] = normalized_email |
| 224 | except Exception: |
| 225 | pass |
| 226 | |
| 227 | if raw_email != normalized_email: |
| 228 | self._log(f"邮箱规范化: {raw_email} -> {normalized_email}") |
| 229 | |
| 230 | # 2. 生成密码 & 用户信息 |
| 231 | self.password = self.password or self._build_password(password_len) |
| 232 | first_name, last_name = generate_random_name() |
| 233 | birthdate = generate_random_birthday() |
| 234 | self._log(f"邮箱: {normalized_email}, 密码: {self.password}") |
| 235 | self._log(f"注册信息: {first_name} {last_name}, 生日: {birthdate}") |
| 236 | |
| 237 | # 3. 邮箱适配器 |
| 238 | email_id = (self.email_info or {}).get("service_id") |
| 239 | skymail_adapter = EmailServiceAdapter(self.email_service, normalized_email, email_id, self._log) |
| 240 | |
| 241 | # 4. 注册状态机 |
no test coverage detected