Skip to content

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:

ParameterTypeRequiredDescription
usernamestringYesUsername
passwordstringYesPassword

Request Example:

json
{
  "username": "admin",
  "password": "chenxi123"
}

Response Example:

json
{
  "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:

ParameterTypeRequiredDescription
usernamestringYesUsername (3-20 alphanumeric characters)
passwordstringYesPassword (6+ characters)
emailstringYesEmail address
captchastringYesVerification code

Request Example:

json
{
  "username": "newuser",
  "password": "password123",
  "email": "newuser@example.com",
  "captcha": "123456"
}

Get Captcha

Endpoint: GET /api/auth/captcha

Response Example:

json
{
  "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:

json
{
  "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:

ParameterTypeRequiredDescription
emailstringNoEmail address
avatarstringNoAvatar URL

Request Example:

json
{
  "email": "newemail@example.com",
  "avatar": "/uploads/avatars/custom.png"
}

Change Password

Endpoint: PUT /api/user/password

Request Parameters:

ParameterTypeRequiredDescription
oldPasswordstringYesOld password
newPasswordstringYesNew password

📤 Upload Record APIs

Get Upload Records List

Endpoint: GET /api/user/uploads

Query Parameters:

ParameterTypeRequiredDescription
pageintegerNoPage number (default: 1)
sizeintegerNoPage size (default: 20)
sortstringNoSort field (e.g., createdAt,desc)

Response Example:

json
{
  "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:

ParameterTypeRequiredDescription
idintegerYesUpload record ID

Batch Delete Upload Records

Endpoint: DELETE /api/user/uploads/batch

Request Parameters:

json
{
  "ids": [1, 2, 3]
}

🔑 API Key Management

Get API Keys List

Endpoint: GET /api/user/apikeys

Response Example:

json
{
  "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:

ParameterTypeRequiredDescription
namestringYesKey name

Response Example:

json
{
  "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:

json
{
  "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 CodeDescriptionPossible Causes
1001Username or password incorrectLogin information incorrect
1002User not foundUser not registered
1003User disabledAccount disabled by administrator
1004Captcha errorCaptcha input error or expired
1005Email already existsEmail already used during registration
1006Username already existsUsername already used during registration
1007Old password incorrectOld password incorrect during password change

🧪 Testing Examples

Complete Login Process

bash
# 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