fix validation messages when registering with existing credentials
This commit is contained in:
parent
04f2e6fa11
commit
8cc799cbc9
|
|
@ -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.',
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ return [
|
|||
'phone_already_verified' => 'Номер телефона уже подтвержден.',
|
||||
'phone_verified_message' => 'Ваш номер телефона подтвержден',
|
||||
'phone_verification_code_invalid' => 'Неверный СМС код',
|
||||
'phone_already_exists' => 'Пользователь с таким номером уже существует.',
|
||||
'email_already_exists' => 'Пользователь с таким email уже существует.',
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue