feature #10

Merged
XiaoLFeng merged 15 commits from feature into master 2023-06-30 16:27:18 +08:00
Showing only changes of commit 01a3c71f02 - Show all commits

View File

@ -264,6 +264,13 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
{ {
/** @var array $returnData Json的 return 返回值 */ /** @var array $returnData Json的 return 返回值 */
// 验证数据 // 验证数据
$dataCheck = Validator::make($request->all(),[
'id' => 'required|int',
'userEmail' => 'required|email',
'userCode' => 'string|min:6|max:64|regex:#^[0-9A-Za-z]+$#',
]);
if ($dataCheck->fails()) {
$resultBlog = DB::table('blog_link') $resultBlog = DB::table('blog_link')
->select('id', 'blogOwnEmail') ->select('id', 'blogOwnEmail')
->find((int)$request->id); ->find((int)$request->id);
@ -293,7 +300,7 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
'code' => $verifyCode, 'code' => $verifyCode,
'type' => 'CODE-CUSTOM-CHECK', 'type' => 'CODE-CUSTOM-CHECK',
'sendTime' => time(), 'sendTime' => time(),
'time' => time()+900, 'time' => time() + 900,
]); ]);
// 数据整理 // 数据整理
$this->sendEmail = [ $this->sendEmail = [
@ -313,9 +320,9 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
// 存在验证码,检查验证码是否需要重新发送 // 存在验证码,检查验证码是否需要重新发送
$data = DB::table('code') $data = DB::table('code')
->where([ ->where([
['email','=',$resultBlog->blogOwnEmail], ['email', '=', $resultBlog->blogOwnEmail],
['type','=','CODE-CUSTOM-CHECK'], ['type', '=', 'CODE-CUSTOM-CHECK'],
['time','>',time()]]) ['time', '>', time()]])
->get() ->get()
->toArray(); ->toArray();
$this->sendEmail = [ $this->sendEmail = [
@ -323,13 +330,13 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
'verifyCode' => $data[0]->code, 'verifyCode' => $data[0]->code,
'sendTime' => time(), 'sendTime' => time(),
]; ];
if ($resultVerifyCode[0]->sendTime < time()-60) { if ($resultVerifyCode[0]->sendTime < time() - 60) {
// 发送验证码 // 发送验证码
DB::table('code') DB::table('code')
->where([ ->where([
['email','=',$resultBlog->blogOwnEmail], ['email', '=', $resultBlog->blogOwnEmail],
['type','=','CODE-CUSTOM-CHECK'], ['type', '=', 'CODE-CUSTOM-CHECK'],
['time','>',time()]]) ['time', '>', time()]])
->update(['sendTime' => time()]); ->update(['sendTime' => time()]);
$this->apiCustomBlogCheckSendEmail(); $this->apiCustomBlogCheckSendEmail();
$returnData = [ $returnData = [
@ -380,6 +387,29 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
], ],
]; ];
} }
} else {
$errorType = array_keys($dataCheck->failed());
$i = 0;
foreach ($dataCheck->failed() as $valueData) {
$errorInfo[$errorType[$i]] = array_keys($valueData);
if ($i == 0) {
$errorSingle = [
'info' => $errorType[$i],
'need' => $errorInfo[$errorType[$i]],
];
}
$i++;
}
$returnData = [
'output' => 'DataFormatError',
'code' => 403,
'data' => [
'message' => '输入内容有错误',
'errorSingle' => $errorSingle,
'error' => $errorInfo,
],
];
}
return Response::json($returnData, $returnData['code']); return Response::json($returnData, $returnData['code']);
} }