From 55170c7693dcba4aa2124fcf416db276e94142ad Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 29 Sep 2022 13:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/docs/slate/source/includes/_users.md | 185 ++++++++++++++ .../api/v1/users/update_email_service.rb | 7 +- public/docs/api.html | 239 ++++++++++++++++++ 3 files changed, 427 insertions(+), 4 deletions(-) diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 318c7930a..e16a52033 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -2304,4 +2304,189 @@ await octokit.request('GET /api/users/:login/applied_projects/:id/refuse.json') "created_at": "2021-06-09 16:41", "time_ago": "7分钟前" } +``` + + +## 用户发送邮件验证码 +用户发送邮件验证码 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/v1/yystopf/send_email_vefify_code.json +``` + +```javascript +await octokit.request('GET /api/v1/:login/send_email_vefify_code.json') +``` + +### HTTP 请求 +`GET /api/v1/:login/send_email_vefify_code.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|login |string |用户标识 | +|code_type |int |10: 更新邮箱| +|email |string |邮箱| +|smscode |string |邮箱md5加密值| + +### 返回字段说明: + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + + +## 用户验证邮件验证码 +用户验证邮件验证码 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/v1/yystopf/check_email_verify_code.json +``` + +```javascript +await octokit.request('POST /api/v1/:login/check_email_verify_code.json') +``` + +### HTTP 请求 +`POST /api/v1/:login/check_email_verify_code.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|login |string |用户标识 | +|code_type |int |10: 更新邮箱| +|email |string |邮箱| +|code |string |邮箱验证码| + +### 返回字段说明: + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + + +## 用户验证密码 +用户验证密码,检查是否和用户密码一致 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/v1/yystopf/check_password.json +``` + +```javascript +await octokit.request('POST /api/v1/:login/check_password.json') +``` + +### HTTP 请求 +`POST /api/v1/:login/check_password.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|login |string |用户标识 | +|password |string |用户密码| + +### 返回字段说明: + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + + +## 用户验证邮箱 +用户验证邮箱是否符合规范以及是否已被使用 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/v1/yystopf/check_email.json +``` + +```javascript +await octokit.request('POST /api/v1/:login/check_email.json') +``` + +### HTTP 请求 +`POST /api/v1/:login/check_email.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|login |string |用户标识 | +|email |string |邮箱地址| + +### 返回字段说明: + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + + +## 用户更改邮箱 +用户更改一个新的邮箱 + +> 示例: + +```shell +curl -X PATCH http://localhost:3000/api/v1/yystopf/update_email.json +``` + +```javascript +await octokit.request('PATCH /api/v1/:login/update_email.json') +``` + +### HTTP 请求 +`PATCH /api/v1/:login/update_email.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|login |string |用户标识 | +|password |string |用户密码| +|email |string |邮箱地址| +|code |string |邮箱验证码| + + +> 请求的JSON示例: + +```json +{ + "password": "Aa19960425.", + "code": "657134", + "email": "yystopf@163.com" +} +``` + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} ``` \ No newline at end of file diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 133693777..e11dd2f61 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -1,10 +1,10 @@ class Api::V1::Users::UpdateEmailService < ApplicationService include ActiveModel::Model - attr_reader :user, :token, :password, :mail, :old_mail, :code, :code_type, :verify_code + attr_reader :user, :token, :password, :mail, :old_mail, :code, :verify_code attr_accessor :gitea_data - validates :password, :code, :code_type, presence: true + validates :password, :code, presence: true validates :mail, presence: true, format: { with: CustomRegexp::EMAIL } def initialize(user, params, token =nil) @@ -14,8 +14,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService @mail = params[:email] @old_mail = user.mail @code = params[:code] - @code_type = params[:code_type] - @verify_code = VerificationCode.where(email: @mail, code: @code, code_type: @code_type).last + @verify_code = VerificationCode.where(email: @mail, code: @code, code_type: 10).last end def call diff --git a/public/docs/api.html b/public/docs/api.html index b41272321..3b0558cd4 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -423,6 +423,21 @@
  • 用户拒绝申请
  • +
  • + 用户发送邮件验证码 +
  • +
  • + 用户验证邮件验证码 +
  • +
  • + 用户验证密码 +
  • +
  • + 用户验证邮箱 +
  • +
  • + 用户更改邮箱 +
  • @@ -4708,6 +4723,230 @@ Success — a happy kitten is an authenticated kitten! "created_at": "2021-06-09 16:41", "time_ago": "7分钟前" } +

    用户发送邮件验证码

    +

    用户发送邮件验证码

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/send_email_vefify_code.json
    +
    await octokit.request('GET /api/v1/:login/send_email_vefify_code.json')
    +

    HTTP 请求

    +

    GET /api/v1/:login/send_email_vefify_code.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    code_typeint10: 更新邮箱
    emailstring邮箱
    smscodestring邮箱md5加密值
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    用户验证邮件验证码

    +

    用户验证邮件验证码

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/v1/yystopf/check_email_verify_code.json
    +
    await octokit.request('POST /api/v1/:login/check_email_verify_code.json')
    +

    HTTP 请求

    +

    POST /api/v1/:login/check_email_verify_code.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    code_typeint10: 更新邮箱
    emailstring邮箱
    codestring邮箱验证码
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    用户验证密码

    +

    用户验证密码,检查是否和用户密码一致

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/v1/yystopf/check_password.json
    +
    await octokit.request('POST /api/v1/:login/check_password.json')
    +

    HTTP 请求

    +

    POST /api/v1/:login/check_password.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    passwordstring用户密码
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    用户验证邮箱

    +

    用户验证邮箱是否符合规范以及是否已被使用

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/v1/yystopf/check_email.json
    +
    await octokit.request('POST /api/v1/:login/check_email.json')
    +

    HTTP 请求

    +

    POST /api/v1/:login/check_email.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    emailstring邮箱地址
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    用户更改邮箱

    +

    用户更改一个新的邮箱

    + +
    +

    示例:

    +
    +
    curl -X PATCH http://localhost:3000/api/v1/yystopf/update_email.json
    +
    await octokit.request('PATCH /api/v1/:login/update_email.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:login/update_email.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    passwordstring用户密码
    emailstring邮箱地址
    codestring邮箱验证码
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "password": "Aa19960425.",
    +    "code": "657134",
    +    "email": "yystopf@163.com"
    +}
    +
    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
     

    Projects

    获取项目邀请链接(项目管理员)

    当前登录(管理员)用户获取项目邀请链接的接口(第一次请求会默认生成role类型为developer和is_apply为true的链接)