用户管理

用户管理


1、获取所有用户信息

  • 需要用户授权验证
  • 返回系统中所有注册的活跃用户。

  • 请求方式

GET /api/users
  • 例子
curl -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users"
  • 响应
Status: 200 OK
Content-Type: application/json
[
  {
    "id": 1,
    "login": "adminuser",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/0f656b0b09d16bafa95064e7e9bd83bc",
    "active": false
  },
  {
    "id": 2,
    "login": "zzl",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/8395226d8e9a44caa3369a541d65e576",
    "active": false
  }
]

2、获取指定用户信息

  • 获取指定用户信息需要查询的用户名。
  • 需要用户授权验证。
  • 请求方式
GET /api/users/{login}
  • 例子
curl -X GET -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users/zzl"
  • 响应
Status: 200 OK
Content-Type: application/json
{
  "id": 2,
  "login": "zzl",
  "email": "[email protected]",
  "avatar_url": "https://secure.gravatar.com/avatar/8395226d8e9a44caa3369a541d65e576",
  "active": false
}

3、创建用户

  • 创建一个新的账户,并返回该用户的详细信息。
  • 需要用户授权验证。
  • 请求方式
POST /api/users/{login}
  • 例子
    我们设置请求体为:
{
  "login": "hand",
  "email": "[email protected]",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "admin": false,
  "active": true
}
curl -X POST -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" -H "Content-Type: application/json" -d '{
  "login": "hand",
  "email": "[email protected]",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "admin": false,
  "active": true
}' "http://192.168.58.13/api/users"
  • 响应
Status: 200 OK
Content-Type: application/json
{
  "id": 3,
  "login": "hand",
  "email": "[email protected]",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "active": true
}

4、更新用户信息

  • 更新一个已存在的用户的信息。
  • 需要用户授权验证。

  • 请求方式

PATCH /api/users/{login}
  • 例子
    我们设置请求体为:
{
  "email": "[email protected]",
  "admin": ture,
  "active": false
}
curl -X PATCH -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" -H "Content-Type: application/json" -d '{
  "email": "[email protected]",
  "admin": true,
  "active": false
}' "http://192.168.58.13/api/users/hand"
  • 响应
Status: 200 OK
Content-Type: application/json; charset=utf-8
{
  "id": 3,
  "login": "hand",
  "email": "[email protected]",
  "avatar_url": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
  "active": false
}

5、删除指定用户

  • 删除指定用户。
  • 需要用户授权验证。

  • 请求方式

DELETE /api/users/{login}
  • 例子
curl -X DELETE -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiYWRtaW51c2VyIiwidHlwZSI6InVzZXIifQ.LNh2Yi-bA7kh56ZLKrTi2GzMIcDkaMVBc8-I9o_UoLU" "http://192.168.58.13/api/users/hand"
  • 响应
Status: 200 OK
Content-Type: text/plain; charset=utf-8

你可能感兴趣的:(用户管理)