用户注册、登录、个人信息等接口。
POST /api/auth/register
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| username | string | 是 | 用户名,3-20字符 |
| email | string | 是 | 邮箱 |
| password | string | 是 | 密码,至少6位 |
{
"username": "user123",
"email": "user@example.com",
"password": "password123"
}
{
"code": 0,
"message": "注册成功",
"data": {
"user": {
"id": 1,
"username": "user123",
"email": "user@example.com",
"nickname": "user123",
"avatar": "",
"create_time": "2025-01-18 10:00:00"
},
"token": "eyJhbGciOiJIUzI1NiIs..."
}
}
POST /api/auth/login
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| username | string | 是 | 用户名或邮箱 |
| password | string | 是 | 密码 |
{
"username": "user123",
"password": "password123"
}
{
"code": 0,
"message": "登录成功",
"data": {
"user": {
"id": 1,
"username": "user123",
"email": "user@example.com",
"nickname": "用户昵称",
"avatar": "/storage/avatars/1.jpg"
},
"token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 604800
}
}
POST /api/auth/logout
Authorization: Bearer {token}
{
"code": 0,
"message": "退出成功"
}
GET /api/auth/user
Authorization: Bearer {token}
{
"code": 0,
"data": {
"id": 1,
"username": "user123",
"email": "user@example.com",
"nickname": "用户昵称",
"avatar": "/storage/avatars/1.jpg",
"bio": "个人简介",
"gender": 1,
"birthday": "1990-01-01",
"mobile": "13800138000",
"status": 1,
"is_admin": false,
"create_time": "2025-01-18 10:00:00",
"stats": {
"photos": 50,
"albums": 5,
"favorites": 100,
"likes": 200
}
}
}
PUT /api/auth/profile
Authorization: Bearer {token}
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| nickname | string | 否 | 昵称 |
| bio | string | 否 | 个人简介 |
| gender | int | 否 | 性别:0未知 1男 2女 |
| birthday | string | 否 | 生日 |
| mobile | string | 否 | 手机号 |
{
"nickname": "新昵称",
"bio": "这是我的简介",
"gender": 1
}
{
"code": 0,
"message": "更新成功",
"data": {
"id": 1,
"nickname": "新昵称",
"bio": "这是我的简介"
}
}
PUT /api/auth/password
Authorization: Bearer {token}
Content-Type: application/json
| 参数 | 类型 | 必填 | 说明 |
|---|
| old_password | string | 是 | 当前密码 |
| new_password | string | 是 | 新密码 |
{
"old_password": "oldpass123",
"new_password": "newpass456"
}
{
"code": 0,
"message": "密码修改成功"
}
POST /api/auth/avatar
Authorization: Bearer {token}
Content-Type: multipart/form-data
{
"code": 0,
"message": "上传成功",
"data": {
"avatar": "/storage/avatars/1.jpg"
}
}
| code | 说明 |
|---|
| 10001 | 用户名已存在 |
| 10002 | 邮箱已存在 |
| 10003 | 用户名或密码错误 |
| 10004 | 账号已被禁用 |
| 10005 | 旧密码错误 |
| 10006 | Token 无效或已过期 |