User Management API
User management related API interfaces, including user authentication, personal information, upload records and other functions.
🔐 Authentication APIs
User Login
Endpoint: POST /api/auth/login
Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| username | string | Yes | Username |
| password | string | Yes | Password |
Request Example:
{
"username": "admin",
"password": "chenxi123"
}Response Example:
{
"code": 200,
"message": "Login successful",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"role": "ADMIN",
"avatar": "/uploads/avatars/default.png",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}User Registration
Endpoint: POST /api/auth/register
Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| username | string | Yes | Username (3-20 alphanumeric characters) |
| password | string | Yes | Password (6+ characters) |
| string | Yes | Email address | |
| captcha | string | Yes | Verification code |
Request Example:
{
"username": "newuser",
"password": "password123",
"email": "newuser@example.com",
"captcha": "123456"
}Get Captcha
Endpoint: GET /api/auth/captcha
Response Example:
{
"code": 200,
"message": "Captcha retrieved successfully",
"data": {
"captchaId": "captcha_123456",
"captchaImage": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"expiresIn": 300
}
}Refresh Token
Endpoint: POST /api/auth/refresh
Request Header:
Authorization: Bearer <refresh-token>👤 User Information APIs
Get User Profile
Endpoint: GET /api/user/profile
Request Header:
Authorization: Bearer <jwt-token>Response Example:
{
"code": 200,
"message": "Retrieved successfully",
"data": {
"id": 1,
"username": "admin",
"email": "admin@example.com",
"role": "ADMIN",
"avatar": "/uploads/avatars/default.png",
"storageUsed": 1024000,
"storageLimit": 104857600,
"uploadCount": 150,
"lastLogin": "2024-01-15T10:30:00Z",
"createdAt": "2024-01-01T00:00:00Z"
}
}Update User Profile
Endpoint: PUT /api/user/profile
Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | Email address | |
| avatar | string | No | Avatar URL |
Request Example:
{
"email": "newemail@example.com",
"avatar": "/uploads/avatars/custom.png"
}Change Password
Endpoint: PUT /api/user/password
Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| oldPassword | string | Yes | Old password |
| newPassword | string | Yes | New password |
📤 Upload Record APIs
Get Upload Records List
Endpoint: GET /api/user/uploads
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| page | integer | No | Page number (default: 1) |
| size | integer | No | Page size (default: 20) |
| sort | string | No | Sort field (e.g., createdAt,desc) |
Response Example:
{
"code": 200,
"message": "Retrieved successfully",
"data": {
"content": [
{
"id": 1,
"filename": "example.jpg",
"originalName": "example.jpg",
"fileSize": 102400,
"fileType": "image/jpeg",
"storageType": "LOCAL",
"url": "http://localhost:8080/uploads/example.jpg",
"thumbnailUrl": "http://localhost:8080/uploads/thumbnails/example.jpg",
"uploadTime": "2024-01-15T10:30:00Z",
"status": "ACTIVE"
}
],
"totalElements": 150,
"totalPages": 8,
"size": 20,
"number": 0,
"first": true,
"last": false
}
}Delete Upload Record
Endpoint: DELETE /api/user/uploads/{id}
Path Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | Upload record ID |
Batch Delete Upload Records
Endpoint: DELETE /api/user/uploads/batch
Request Parameters:
{
"ids": [1, 2, 3]
}🔑 API Key Management
Get API Keys List
Endpoint: GET /api/user/apikeys
Response Example:
{
"code": 200,
"message": "Retrieved successfully",
"data": [
{
"id": 1,
"name": "Web Application",
"key": "ak_xxxxxxxxxxxxxxxx",
"createdAt": "2024-01-01T00:00:00Z",
"lastUsed": "2024-01-15T10:30:00Z",
"status": "ACTIVE"
}
]
}Create API Key
Endpoint: POST /api/user/apikeys
Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Key name |
Response Example:
{
"code": 200,
"message": "Created successfully",
"data": {
"id": 2,
"name": "Mobile App",
"key": "ak_yyyyyyyyyyyyyyyy",
"createdAt": "2024-01-16T10:30:00Z",
"status": "ACTIVE"
}
}Delete API Key
Endpoint: DELETE /api/user/apikeys/{id}
📊 Statistics
Get User Statistics
Endpoint: GET /api/user/stats
Response Example:
{
"code": 200,
"message": "Retrieved successfully",
"data": {
"totalUploads": 150,
"todayUploads": 5,
"storageUsed": 1024000,
"storageLimit": 104857600,
"storageUsage": "0.98%",
"uploadTrends": [
{
"date": "2024-01-15",
"count": 12
},
{
"date": "2024-01-14",
"count": 8
}
]
}
}⚠️ Error Codes
| Error Code | Description | Possible Causes |
|---|---|---|
| 1001 | Username or password incorrect | Login information incorrect |
| 1002 | User not found | User not registered |
| 1003 | User disabled | Account disabled by administrator |
| 1004 | Captcha error | Captcha input error or expired |
| 1005 | Email already exists | Email already used during registration |
| 1006 | Username already exists | Username already used during registration |
| 1007 | Old password incorrect | Old password incorrect during password change |
🧪 Testing Examples
Complete Login Process
# 1. User login
curl -X POST "http://localhost:8080/api/auth/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "chenxi123"
}'
# 2. Get user profile
curl -X GET "http://localhost:8080/api/user/profile" \
-H "Authorization: Bearer <token-from-step1>"
# 3. Get upload records
curl -X GET "http://localhost:8080/api/user/uploads?page=1&size=10" \
-H "Authorization: Bearer <token-from-step1>"🔄 Changelog
v1.0.0 (2024-01-01)
- User authentication APIs (login, register, captcha)
- User information management APIs
- Upload record management APIs
- API key management APIs
- User statistics APIs
🔗 Related Links: API Overview