diff --git a/modules/system/lang/en/validation.php b/modules/system/lang/en/validation.php index 93a81b984..1be1e2dbb 100644 --- a/modules/system/lang/en/validation.php +++ b/modules/system/lang/en/validation.php @@ -156,6 +156,8 @@ return [ 'phone_already_verified' => 'You have already verified your phone number.', 'phone_verified_message' => 'Your phone number has been succesfully verified', 'phone_verification_code_invalid' => 'Invalid sms code', + 'phone_already_exists' => 'This phone number has already been taken.', + 'email_already_exists' => 'This email has already been taken.', ], /* diff --git a/modules/system/lang/ru/validation.php b/modules/system/lang/ru/validation.php index bd4d90341..ee1e79083 100644 --- a/modules/system/lang/ru/validation.php +++ b/modules/system/lang/ru/validation.php @@ -156,6 +156,8 @@ return [ 'phone_already_verified' => 'Номер телефона уже подтвержден.', 'phone_verified_message' => 'Ваш номер телефона подтвержден', 'phone_verification_code_invalid' => 'Неверный СМС код', + 'phone_already_exists' => 'Пользователь с таким номером уже существует.', + 'email_already_exists' => 'Пользователь с таким email уже существует.', ], /* diff --git a/modules/system/lang/tm/validation.php b/modules/system/lang/tm/validation.php index dede076bd..6bce37056 100644 --- a/modules/system/lang/tm/validation.php +++ b/modules/system/lang/tm/validation.php @@ -158,6 +158,8 @@ return [ 'phone_already_verified' => 'Siziň telefon belgiňiz eýýäm tassyklanan.', 'phone_verified_message' => 'Siziň telefon belgiňiz tassyklandy', 'phone_verification_code_invalid' => 'Nädogry SMS kody', + 'phone_already_exists' => 'Bu belgi öňden hasaba alyndy.', + 'email_already_exists' => 'Bu el. bukja öňden hasaba alyndy.', ], /* diff --git a/plugins/vdomah/jwtauth/routes.php b/plugins/vdomah/jwtauth/routes.php index 52112e2e2..bcb7691f1 100644 --- a/plugins/vdomah/jwtauth/routes.php +++ b/plugins/vdomah/jwtauth/routes.php @@ -163,15 +163,33 @@ Route::group(['prefix' => 'api'], function() { 'dial_code' => 'required', ]; + $messages = [ + 'email.unique' => [ + 'ru' => trans('validation.api.email_already_exists', [], 'ru'), + 'en' => trans('validation.api.email_already_exists', [], 'en'), + 'tm' => trans('validation.api.email_already_exists', [], 'tm'), + ], + 'username.unique' => [ + 'ru' => trans('validation.api.phone_already_exists', [], 'ru'), + 'en' => trans('validation.api.phone_already_exists', [], 'en'), + 'tm' => trans('validation.api.phone_already_exists', [], 'tm'), + ], + ]; + // username should be concatenated with username in order to check - validate // if a user (with dial_code + username) already exists $credentialsToValidate = array_merge($credentials,[ 'username' => $credentials['dial_code'] . $credentials['username'] ]); - $validation = \Validator::make($credentialsToValidate, $rules,(new UserModel)->messages); + $validation = \Validator::make($credentialsToValidate, $rules, $messages); if ($validation->fails()) { - return Response::json(['error' => $validation->errors()], 400); + + $errorResponse = $validation->errors(); + + $errorResponse = reset($errorResponse); + + return Response::json(['error' => reset($errorResponse)[0]], 400); } /**