lty/qy_lty/userapp/README.md
2026-03-17 13:17:02 +08:00

69 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 用户管理模块 (userapp)
## 概述
用户管理模块提供了完整的用户账号管理功能,包括:
- 多种方式的用户注册(用户名注册)
- 多种方式的用户登录(用户名登录、邮箱登录、手机验证码登录)
- 用户信息管理
- 密码重置
- 第三方账号登录(通过 allauth 支持)
## API 文档
详细的API文档请参考
- [用户认证API文档](../docs/user_authentication_api.md) - 包含所有认证相关接口
- Swagger API文档运行服务后访问 `/swagger/` 路径
## 认证方式
系统支持两种认证方式:
1. **Token认证**基于自定义的Redis存储Token用于API访问
2. **Session认证**基于Django内置的session机制主要用于管理后台
## 目录结构
```
userapp/
├── models.py # 用户模型定义
├── views.py # API视图
├── serializers.py # 序列化器
├── urls.py # URL路由配置
├── utils.py # 工具函数
└── authentication.py # 自定义认证类
```
## 登录注册流程
### 注册流程
1. 用户名注册:
- 访问 `/api/user/auth/register/`
- 提供用户名、密码、确认密码
- 可选提供邮箱和手机号
### 登录流程
系统支持多种登录方式:
1. 用户名登录:
- 访问 `/api/user/auth/username/login/`
- 提供用户名和密码
- 获取返回的令牌Token
2. 邮箱登录:
- 访问 `/api/user/auth/email/login/`
- 提供邮箱和密码
- 获取返回的令牌Token
3. 手机验证码登录:
- 先访问 `/api/user/auth/phone/verify/` 获取验证码
- 然后访问 `/api/user/auth/phone/login/` 提供手机号和验证码
- 获取返回的令牌Token
### 使用令牌
获取令牌后,在后续请求中添加以下请求头:
```
Authorization: Bearer {token}
```