Mangogo 营业厅Mangogo 营业厅
首页API 参考Skills插件

3.7 邮箱修改

POST/api/oauth/email/change

3.7 邮箱修改

邮箱修改

接口地址: POST /api/oauth/email/change

权限要求: 🔐 需要登录(User权限)

描述: 修改邮箱

请求头:

token: {access_token}

请求头说明:

  • token (必填): 访问令牌

请求参数:

  • old_email (string, 必填): 原邮箱
  • old_code (string, 必填): 原邮箱验证码(type 为 change_email)
  • new_email (string, 必填): 新邮箱
  • new_code (string, 必填): 新邮箱验证码(type 为 bind_change_email)

请求示例:

curl -X POST "https://your-domain.com/api/oauth/email/change" \  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \  -H "Content-Type: application/json" \  -d '{    "old_email": "old@example.com",    "old_code": "123456",    "new_email": "new@example.com",    "new_code": "654321"  }'

实现逻辑:

  1. 第一步:根据原邮箱和原邮箱验证码查询 email_verifications 表,条件为:
    • email = 原邮箱
    • type = change_email
    • is_used = false
    • expired_at > 当前时间(未过期)
  2. 如果查询结果存在且验证码匹配,则第一步验证通过
  3. 第二步:根据新邮箱和新邮箱验证码查询 email_verifications 表,条件为:
    • email = 新邮箱
    • type = bind_change_email
    • is_used = false
    • expired_at > 当前时间(未过期)
  4. 如果查询结果存在且验证码匹配,则第二步验证通过
  5. 当第一步和第二步都验证通过后,将两个邮箱的所有验证码的 is_used 都设置为 true
  6. 检查新邮箱是否已被其他用户使用
  7. 更新当前用户的邮箱
  8. 返回修改成功

返回数据:

{  "success": true,  "message": ""}