From d898bedfe5bb1bdfc378fd24acc4abaeb7315e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Wed, 10 Nov 2021 11:42:07 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9B=BB=E8=A9=B1=E7=95=AA=E5=8F=B7=E3=81=AE?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ChildrenController.php | 37 +++++++++++++++++-- .../Controllers/Api/FathersController.php | 25 ++++++++++++- backend/resources/lang/ja/validation.php | 5 ++- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/backend/app/Http/Controllers/Api/ChildrenController.php b/backend/app/Http/Controllers/Api/ChildrenController.php index 65f66ffb..dd34554d 100644 --- a/backend/app/Http/Controllers/Api/ChildrenController.php +++ b/backend/app/Http/Controllers/Api/ChildrenController.php @@ -29,9 +29,20 @@ class ChildrenController extends Controller { } public function registerTemporary (Request $r) { + // 電話番号の文字数。 + Validator::extend('tel_size', function ($attribute, $value, $params, $validator) { + try { + return strlen((string)$value) == 10 || strlen((string)$value) == 11; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + $validate = Validator::make($r->all(), [ - 'tel' => 'required|unique:children|numeric|digits_between:0,99999999999|starts_with:0' + 'tel' => 'required|unique:children|numeric|starts_with:0|tel_size' ]); + if ($validate->fails()) { // バリデーションエラー return ['status_code' => 422, 'error_messages' => $validate->errors()]; @@ -155,8 +166,18 @@ KIKI承知システムを使って「聞いてない!」「言ってない! } public function requestPassword (Request $r) { + // 電話番号の文字数。 + Validator::extend('tel_size', function ($attribute, $value, $params, $validator) { + try { + return strlen((string)$value) == 10 || strlen((string)$value) == 11; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + $validate = Validator::make($r->all(), [ - 'tel' => 'required|numeric|digits_between:0,99999999999|starts_with:0', + 'tel' => 'required|numeric|starts_with:0|tel_size' ]); if ($validate->fails()) { @@ -395,10 +416,20 @@ https://kikikan.jp/c-account/forgot-password/reset/'.$token; return ['status_code' => 400, 'error_messages' => ['子の更新に失敗しました。']]; } + // 電話番号の文字数。 + Validator::extend('tel_size', function ($attribute, $value, $params, $validator) { + try { + return strlen((string)$value) == 10 || strlen((string)$value) == 11; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + // バリデーションエラー $validate = Validator::make($r->all(), [ 'email' => 'required|max:255|email', - 'tel' => 'required|numeric|digits_between:0,99999999999|starts_with:0', + 'tel' => 'required|numeric|starts_with:0|tel_size', 'last_name' => 'required|max:100', 'first_name' => 'required|max:100', 'identity' => 'required|max:20|alpha_num', diff --git a/backend/app/Http/Controllers/Api/FathersController.php b/backend/app/Http/Controllers/Api/FathersController.php index 1ba34c52..099e3bec 100644 --- a/backend/app/Http/Controllers/Api/FathersController.php +++ b/backend/app/Http/Controllers/Api/FathersController.php @@ -113,14 +113,25 @@ class FathersController extends Controller { } public function registerMain (Request $r) { + // 電話番号の文字数。 + Validator::extend('tel_size', function ($attribute, $value, $params, $validator) { + try { + return strlen((string)$value) == 10 || strlen((string)$value) == 11; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + $validate = Validator::make($r->all(), [ 'token' => 'required', 'password' => 'required|min:8|max:72|confirmed', 'company' => 'max:100', 'image' => 'max:1024|mimes:jpg,png,gif', 'profile' => 'max:1000', - 'tel' => 'required|unique:children|numeric|digits_between:0,99999999999|starts_with:0', + 'tel' => 'required|unique:fathers|numeric|starts_with:0|tel_size', ]); + if ($validate->fails()) { // バリデーションエラー return ['status_code' => 422, 'error_messages' => $validate->errors()]; @@ -310,12 +321,22 @@ class FathersController extends Controller { return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']]; } + // 電話番号の文字数。 + Validator::extend('tel_size', function ($attribute, $value, $params, $validator) { + try { + return strlen((string)$value) == 10 || strlen((string)$value) == 11; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + // バリデーションエラー $validate = Validator::make($r->all(), [ 'email' => 'required|max:255|email', 'company' => 'max:100', 'profile' => 'max:1000', - 'tel' => 'required|numeric|digits_between:0,99999999999|starts_with:0', + 'tel' => 'required|numeric|starts_with:0|tel_size' ]); if ($validate->fails()) { diff --git a/backend/resources/lang/ja/validation.php b/backend/resources/lang/ja/validation.php index 527f687f..4993d7e3 100644 --- a/backend/resources/lang/ja/validation.php +++ b/backend/resources/lang/ja/validation.php @@ -24,9 +24,9 @@ return [ 'before' => 'The :attribute must be a date before :date.', 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 'between' => [ - 'numeric' => 'The :attribute must be between :min and :max.', + 'numeric' => ' :attribute は :min ・ :max 文字です。', 'file' => 'The :attribute must be between :min and :max kilobytes.', - 'string' => 'The :attribute must be between :min and :max characters.', + 'string' => ' :attribute は :min ・ :max 文字です。', 'array' => 'The :attribute must have between :min and :max items.', ], 'boolean' => 'The :attribute field must be true or false.', @@ -119,6 +119,7 @@ return [ ], 'starts_with' => 'The :attribute must start with one of the following: :values.', 'string' => 'The :attribute must be a string.', + 'tel_size' => '電話番号は10・11文字です。', 'timezone' => 'The :attribute must be a valid zone.', 'unique' => '同じ :attribute は使用できません。', 'uploaded' => 'The :attribute failed to upload.',