博客验证检查添加校验组件

Signed-off-by: XiaoLFeng <gm@x-lf.cn>
This commit is contained in:
筱锋xiao_lfeng 2023-06-30 10:01:41 +08:00
parent 7bf090d6e6
commit 01a3c71f02

View File

@ -264,6 +264,13 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
{
/** @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')
->select('id', 'blogOwnEmail')
->find((int)$request->id);
@ -293,7 +300,7 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
'code' => $verifyCode,
'type' => 'CODE-CUSTOM-CHECK',
'sendTime' => time(),
'time' => time()+900,
'time' => time() + 900,
]);
// 数据整理
$this->sendEmail = [
@ -313,9 +320,9 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
// 存在验证码,检查验证码是否需要重新发送
$data = DB::table('code')
->where([
['email','=',$resultBlog->blogOwnEmail],
['type','=','CODE-CUSTOM-CHECK'],
['time','>',time()]])
['email', '=', $resultBlog->blogOwnEmail],
['type', '=', 'CODE-CUSTOM-CHECK'],
['time', '>', time()]])
->get()
->toArray();
$this->sendEmail = [
@ -323,13 +330,13 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse
'verifyCode' => $data[0]->code,
'sendTime' => time(),
];
if ($resultVerifyCode[0]->sendTime < time()-60) {
if ($resultVerifyCode[0]->sendTime < time() - 60) {
// 发送验证码
DB::table('code')
->where([
['email','=',$resultBlog->blogOwnEmail],
['type','=','CODE-CUSTOM-CHECK'],
['time','>',time()]])
['email', '=', $resultBlog->blogOwnEmail],
['type', '=', 'CODE-CUSTOM-CHECK'],
['time', '>', time()]])
->update(['sendTime' => time()]);
$this->apiCustomBlogCheckSendEmail();
$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']);
}