diff --git a/modules/system/lang/en/validation.php b/modules/system/lang/en/validation.php index e359ac1a9..e5af7c097 100644 --- a/modules/system/lang/en/validation.php +++ b/modules/system/lang/en/validation.php @@ -140,6 +140,9 @@ return [ 'new_message' => 'New message', 'payment_reviewed' => 'Payment has been reviewed', 'product_reviewed' => 'Post has been reviewed', + 'api' => [ + 'sign_up_excp' => 'Registration error', + ], /* |-------------------------------------------------------------------------- diff --git a/modules/system/lang/ru/validation.php b/modules/system/lang/ru/validation.php index 0d985bdb8..bc25a10af 100644 --- a/modules/system/lang/ru/validation.php +++ b/modules/system/lang/ru/validation.php @@ -140,6 +140,9 @@ return [ 'new_message' => 'Новое сообщение', 'payment_reviewed' => 'Платеж рассмотрен', 'product_reviewed' => 'Объявление рассмотрено', + 'api' => [ + 'sign_up_excp' => 'Ошибка при регистрации', + ], /* |-------------------------------------------------------------------------- diff --git a/modules/system/lang/tm/validation.php b/modules/system/lang/tm/validation.php index ff51eb1b1..3d7dbc2c9 100644 --- a/modules/system/lang/tm/validation.php +++ b/modules/system/lang/tm/validation.php @@ -142,6 +142,9 @@ return [ 'new_message' => 'Täze hat', 'payment_reviewed' => 'Töleg gözden geçirildi', 'product_reviewed' => 'Bildiriş gözden geçirildi', + 'api' => [ + 'sign_up_excp' => 'Hasaba alyş ýalňyşy', + ], /* |-------------------------------------------------------------------------- diff --git a/plugins/vdomah/jwtauth/routes.php b/plugins/vdomah/jwtauth/routes.php index da7684ed2..b75122faf 100644 --- a/plugins/vdomah/jwtauth/routes.php +++ b/plugins/vdomah/jwtauth/routes.php @@ -109,11 +109,16 @@ Route::group(['prefix' => 'api'], function() { $credentials = Input::only($login_fields); $rules = [ - 'email' => 'required|between:6,191|email', - 'username' => 'required|digits_between:8,20|numeric', + 'email' => 'required|between:6,191|email|unique:users', + 'username' => 'required|numeric|unique:users', 'dial_code' => 'required', ]; + // to check username + $credentials = array_merge($credentials,[ + 'username' => $credentials['dial_code'] . $credentials['username'] + ]); + $validation = \Validator::make($credentials, $rules,(new UserModel)->messages); if ($validation->fails()) { return Response::json(['error' => $validation->errors()], 400); @@ -130,9 +135,7 @@ Route::group(['prefix' => 'api'], function() { if (!array_key_exists('password_confirmation', $credentials) && array_key_exists('password', $credentials)) { $credentials['password_confirmation'] = $credentials['password']; } - $userModel = Auth::register(array_merge($credentials,[ - 'username' => $credentials['dial_code'] . $credentials['username'] - ]), $automaticActivation); + $userModel = Auth::register($credentials, $automaticActivation); if ($userModel->methodExists('getAuthApiSignupAttributes')) { $user = $userModel->getAuthApiSignupAttributes(); @@ -151,7 +154,14 @@ Route::group(['prefix' => 'api'], function() { ]; } } catch (Exception $e) { - return Response::json(['error' => $e->getMessage()], 401); + + \Log::info($e->getMessage()); + + return Response::json(['error' => [ + 'ru' => trans('validation.api.sign_up_excp', [], 'ru'), + 'en' => trans('validation.api.sign_up_excp', [], 'en'), + 'tm' => trans('validation.api.sign_up_excp', [], 'tm'), + ]], 401); } $token = JWTAuth::fromUser($userModel);