Files
DP/tempdocs/邮箱验证与密码重置接口文档.md

138 lines
2.8 KiB
Markdown

# DesignerCEP 邮箱验证与密码重置接口文档
本文档描述了最新的注册验证流程和密码重置流程。
## 1. 注册流程 (单表单模式)
新版注册流程改为在同一个表单中完成:输入邮箱 -> 发送验证码 -> 填写验证码及密码 -> 提交注册。
### 1.1 发送注册验证码
用户输入邮箱后,点击“发送验证码”按钮调用此接口。
- **接口地址**: `/api/v1/auth/send-verification-code`
- **请求方式**: `POST`
- **Content-Type**: `application/json`
**请求参数**:
```json
{
"email": "user@example.com"
}
```
**响应示例 (成功)**:
```json
{
"detail": "验证码已发送"
}
```
**响应示例 (失败)**:
- 400 Bad Request: "该邮箱已被注册"
- 500 Internal Server Error: "邮件发送失败: ..."
---
### 1.2 提交注册
用户填写收到的 6 位数字验证码、用户名、密码后,调用此接口完成注册。
- **接口地址**: `/api/v1/auth/register`
- **请求方式**: `POST`
- **Content-Type**: `application/json`
**请求参数**:
```json
{
"username": "myusername",
"email": "user@example.com",
"password": "mypassword123",
"confirm_password": "mypassword123",
"code": "123456",
"device_id": "device_unique_id"
}
```
*注:`device_id` 为可选,若不传默认为 "unknown_device"*
**响应示例 (成功)**:
```json
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer",
"username": "myusername"
}
```
**响应示例 (失败)**:
- 400 Bad Request: "请先发送验证码" (如果邮箱未先调用发送接口)
- 400 Bad Request: "验证码错误"
- 400 Bad Request: "验证码已过期"
- 400 Bad Request: "用户名已存在"
---
## 2. 找回/重置密码流程
密码重置流程改为使用 6 位数字验证码,而非之前的长链接。
### 2.1 发送重置验证码
用户在“忘记密码”页面输入邮箱,点击发送。
- **接口地址**: `/api/v1/auth/forgot-password`
- **请求方式**: `POST`
- **Content-Type**: `application/json`
**请求参数**:
```json
{
"email": "user@example.com"
}
```
**响应示例**:
```json
{
"detail": "如果邮箱存在,重置邮件已发送"
}
```
---
### 2.2 重置密码
用户输入收到的 6 位验证码和新密码进行重置。
- **接口地址**: `/api/v1/auth/reset-password`
- **请求方式**: `POST`
- **Content-Type**: `application/json`
**请求参数**:
```json
{
"email": "user@example.com",
"token": "123456",
"new_password": "newpassword123",
"confirm_password": "newpassword123"
}
```
*注:`token` 字段即为邮件中收到的 6 位数字验证码*
**响应示例 (成功)**:
```json
{
"detail": "密码重置成功"
}
```
**响应示例 (失败)**:
- 400 Bad Request: "验证码错误"
- 400 Bad Request: "验证码已过期"
- 400 Bad Request: "两次输入的密码不一致"
- 404 Not Found: "用户不存在"