Some Refactoring Done

This commit is contained in:
devansh bawari 2021-07-02 11:09:40 +05:30
parent 63f4d88dee
commit b746987075
4 changed files with 33 additions and 19 deletions

View File

@ -125,6 +125,33 @@ class Captcha implements CaptchaContract
return json_decode($response->getBody())->success;
}
/**
* Get or merge existing validations with your captcha validations.
*
* @return array
*/
public function getValidations($rules = []): array
{
return $this->isActive()
? array_merge($rules, ['g-recaptcha-response' => 'required|captcha'])
: $rules;
}
/**
* Get or merge existing validation messages with your captcha validation messages.
*
* @return array
*/
public function getValidationMessages($messages = []): array
{
return $this->isActive()
? array_merge($messages, [
'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required'),
'g-recaptcha-response.captcha' => __('customer::app.admin.system.captcha.validations.captcha')
])
: $messages;
}
/**
* Get attributes.
*

View File

@ -33,9 +33,7 @@ class CustomerForgotPasswordRequest extends FormRequest
*/
public function rules()
{
return Captcha::isActive()
? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha'])
: $this->rules;
return Captcha::getValidations($this->rules);
}
/**
@ -45,9 +43,6 @@ class CustomerForgotPasswordRequest extends FormRequest
*/
public function messages()
{
return [
'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required'),
'g-recaptcha-response.captcha' => __('customer::app.admin.system.captcha.validations.captcha')
];
return Captcha::getValidationMessages();
}
}

View File

@ -34,9 +34,7 @@ class CustomerLoginRequest extends FormRequest
*/
public function rules()
{
return Captcha::isActive()
? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha'])
: $this->rules;
return Captcha::getValidations($this->rules);
}
/**
@ -46,8 +44,6 @@ class CustomerLoginRequest extends FormRequest
*/
public function messages()
{
return [
'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required')
];
return Captcha::getValidationMessages();
}
}

View File

@ -36,9 +36,7 @@ class CustomerRegistrationRequest extends FormRequest
*/
public function rules()
{
return Captcha::isActive()
? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha'])
: $this->rules;
return Captcha::getValidations($this->rules);
}
/**
@ -48,8 +46,6 @@ class CustomerRegistrationRequest extends FormRequest
*/
public function messages()
{
return [
'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required')
];
return Captcha::getValidationMessages();
}
}