优化代码

main
gzydong 2021-05-24 19:03:27 +08:00
parent dabf8b39c9
commit 270f8c2ff7
7 changed files with 47 additions and 12 deletions

View File

@ -43,7 +43,7 @@ class AuthController extends CController
{
$params = $this->request->inputs(['mobile', 'password', 'platform']);
$this->validate($params, [
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'mobile' => "required|phone",
'password' => 'required',
'platform' => 'required|in:h5,ios,windows,mac,web',
]);
@ -94,7 +94,7 @@ class AuthController extends CController
$params = $this->request->all();
$this->validate($params, [
'nickname' => "required|max:20",
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'mobile' => "required|phone",
'password' => 'required|max:16',
'sms_code' => 'required|digits:6',
'platform' => 'required|in:h5,ios,windows,mac,web',
@ -128,7 +128,7 @@ class AuthController extends CController
{
$params = $this->request->inputs(['mobile', 'password', 'sms_code']);
$this->validate($params, [
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'mobile' => "required|phone",
'password' => 'required|max:16',
'sms_code' => 'required|digits:6',
]);
@ -175,7 +175,7 @@ class AuthController extends CController
$params = $this->request->inputs(['type', 'mobile']);
$this->validate($params, [
'type' => "required",
'mobile' => "required|regex:/^1[345789][0-9]{9}$/"
'mobile' => "required|phone"
]);
if (!$this->smsCodeService->isUsages($params['type'])) {

View File

@ -184,7 +184,7 @@ class UsersController extends CController
{
$params = $this->request->inputs(['mobile', 'password', 'sms_code']);
$this->validate($params, [
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'mobile' => "required|phone",
'password' => 'required',
'sms_code' => 'required|digits:6'
]);
@ -256,7 +256,7 @@ class UsersController extends CController
{
$params = $this->request->inputs(['mobile']);
$this->validate($params, [
'mobile' => "present|regex:/^1[345789][0-9]{9}$/"
'mobile' => "present|phone"
]);
$user_id = $this->uid();

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
/**
* 测试相关控制器
* @Controller()
* @package App\Controller
*/
class TestController extends AbstractController
{
/**
* @RequestMapping(path="indexss", methods="get")
*/
public function index()
{
return $this->response->json([
'code' => 200
]);
}
}

View File

@ -57,6 +57,10 @@ class AppExceptionHandler extends ExceptionHandler
*/
public function sendAdminEmail(Throwable $throwable)
{
if (config('app_env') != 'dev') {
return;
}
$error = implode(':', [
'error',
md5($throwable->getFile() . $throwable->getCode() . $throwable->getLine()),

View File

@ -26,17 +26,21 @@ class ValidatorFactoryResolvedListener implements ListenerInterface
$validatorFactory = $event->validatorFactory;
// 注册了 ids 验证器(验证英文逗号拼接的整形数字字符串 例如:[1,2,3,4,5])
$validatorFactory->extend('ids', function ($attribute, $value, $parameters, $validator) {
if (!is_string($value)) {
return false;
}
$validatorFactory->extend('ids', function ($attribute, $value) {
if (!is_string($value)) return false;
$arr = explode(',', $value);
foreach ($arr as $id) {
foreach (explode(',', $value) as $id) {
if (!check_int($id)) return false;
}
return true;
});
// 注册手机号验证器
$validatorFactory->extend('phone', function ($attribute, $value) {
if (!is_string($value)) return false;
return (bool)preg_match('/^1[345789][0-9]{9}$/', $value);
});
}
}

View File

@ -176,4 +176,5 @@ return [
'sequential_array' => 'The :attribute must be sequential array',
'ids' => ' :attribute 字段 ids 格式不正确',
'phone' => 'The :attribute must be a valid phone number',
];

View File

@ -176,4 +176,5 @@ return [
'sequential_array' => ':attribute 必须是一个有序数组',
'ids' => ' :attribute 字段 ids 格式不正确',
'phone' => ':attribute 必须为一个有效的电话号码',
];