门户端接口【内部使用】3、个人中心
3.7 邮箱修改
POST
/api/oauth/email/change3.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" }'实现逻辑:
- 第一步:根据原邮箱和原邮箱验证码查询
email_verifications表,条件为:email= 原邮箱type=change_emailis_used=falseexpired_at> 当前时间(未过期)
- 如果查询结果存在且验证码匹配,则第一步验证通过
- 第二步:根据新邮箱和新邮箱验证码查询
email_verifications表,条件为:email= 新邮箱type=bind_change_emailis_used=falseexpired_at> 当前时间(未过期)
- 如果查询结果存在且验证码匹配,则第二步验证通过
- 当第一步和第二步都验证通过后,将两个邮箱的所有验证码的
is_used都设置为true - 检查新邮箱是否已被其他用户使用
- 更新当前用户的邮箱
- 返回修改成功
返回数据:
{ "success": true, "message": ""}