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 @@
用户发送邮件验证码
+ +++示例:
+
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')
+
GET /api/v1/:login/send_email_vefify_code.json
参数 | +类型 | +字段说明 | +
---|---|---|
login | +string | +用户标识 | +
code_type | +int | +10: 更新邮箱 | +
string | +邮箱 | +|
smscode | +string | +邮箱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')
+
POST /api/v1/:login/check_email_verify_code.json
参数 | +类型 | +字段说明 | +
---|---|---|
login | +string | +用户标识 | +
code_type | +int | +10: 更新邮箱 | +
string | +邮箱 | +|
code | +string | +邮箱验证码 | +
++返回的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')
+
POST /api/v1/:login/check_password.json
参数 | +类型 | +字段说明 | +
---|---|---|
login | +string | +用户标识 | +
password | +string | +用户密码 | +
++返回的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')
+
POST /api/v1/:login/check_email.json
参数 | +类型 | +字段说明 | +
---|---|---|
login | +string | +用户标识 | +
string | +邮箱地址 | +
++返回的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')
+
PATCH /api/v1/:login/update_email.json
参数 | +类型 | +字段说明 | +
---|---|---|
login | +string | +用户标识 | +
password | +string | +用户密码 | +
string | +邮箱地址 | +|
code | +string | +邮箱验证码 | +
++请求的JSON示例:
+
{
+ "password": "Aa19960425.",
+ "code": "657134",
+ "email": "yystopf@163.com"
+}
+
++返回的JSON示例:
+
{
+ "status": 0,
+ "message": "success"
+}
当前登录(管理员)用户获取项目邀请链接的接口(第一次请求会默认生成role类型为developer和is_apply为true的链接)