Validations Added In The Backends

This commit is contained in:
Devansh 2021-11-22 11:03:02 +05:30
parent a7f41506aa
commit 9c0fb49611
13 changed files with 98 additions and 36 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace Webkul\Core\Contracts\Validations;
use Illuminate\Contracts\Validation\Rule;
class AlphaNumericSpace implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return preg_match('/^[a-zA-Z0-9\s]+$/', $value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return trans('core::validation.alpha-numeric-space');
}
}

View File

@ -5,4 +5,4 @@ return [
'template' => 'Template',
'parents' => 'Parents'
]
];
];

View File

@ -1,7 +1,8 @@
<?php
return [
'slug' => 'The :attribute must be valid slug.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.'
];
'decimal' => 'The :attribute must be valid.',
'slug' => 'The :attribute must be valid slug.',
];

View File

@ -1,7 +1,8 @@
<?php
return [
'slug' => 'O :attribute debe tener un slug válido.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute debe ser válido.',
'decimal' => 'O :attribute debe ser válido.'
];
'decimal' => 'O :attribute debe ser válido.',
'slug' => 'O :attribute debe tener un slug válido.',
];

View File

@ -0,0 +1,8 @@
<?php
return [
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.',
'slug' => 'The :attribute must be valid slug.',
];

View File

@ -0,0 +1,8 @@
<?php
return [
'path-hint' => [
'template' => 'Template',
'parents' => 'Parents'
]
];

View File

@ -1,7 +1,8 @@
<?php
return [
'slug' => ':attribute deve essere uno slug valido.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute deve essere valido.',
'decimal' => ':attribute deve essere valido.'
];
'decimal' => ':attribute deve essere valido.',
'slug' => ':attribute deve essere uno slug valido.',
];

View File

@ -0,0 +1,8 @@
<?php
return [
'path-hint' => [
'template' => 'Template',
'parents' => 'Parents'
]
];

View File

@ -1,7 +1,8 @@
<?php
return [
'slug' => 'O :attribute precisa ter um slug válido.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute precisa ser válido.',
'decimal' => 'O :attribute precisa ser válido.'
];
'decimal' => 'O :attribute precisa ser válido.',
'slug' => 'O :attribute precisa ter um slug válido.',
];

View File

@ -0,0 +1,8 @@
<?php
return [
'path-hint' => [
'template' => 'Template',
'parents' => 'Parents'
]
];

View File

@ -1,7 +1,8 @@
<?php
return [
'slug' => ':attribute değeri geçerli bir url olmalı.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute değeri geçerli olmalı.',
'decimal' => ':attribute geçerli olmalı.'
'decimal' => ':attribute geçerli olmalı.',
'slug' => ':attribute değeri geçerli bir url olmalı.',
];

View File

@ -1,6 +0,0 @@
<?php
return [
'name' => 'Webkul Bagisto Core',
'version' => '0.0.1',
];

View File

@ -5,36 +5,37 @@ namespace Webkul\Customer\Http\Controllers;
use Hash;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Webkul\Shop\Mail\SubscriptionEmail;
use Webkul\Core\Contracts\Validations\AlphaNumericSpace;
use Webkul\Core\Repositories\SubscribersListRepository;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Repositories\ProductReviewRepository;
use Webkul\Core\Repositories\SubscribersListRepository;
use Webkul\Shop\Mail\SubscriptionEmail;
class CustomerController extends Controller
{
/**
* Contains route related configuration
* Contains route related configuration.
*
* @var array
*/
protected $_config;
/**
* CustomerRepository object
* Customer repository instance.
*
* @var \Webkul\Customer\Repositories\CustomerRepository
*/
protected $customerRepository;
/**
* ProductReviewRepository object
* Product review repository instance.
*
* @var \Webkul\Customer\Repositories\ProductReviewRepository
*/
protected $productReviewRepository;
/**
* SubscribersListRepository
* Subscribers list repository instance.
*
* @var \Webkul\Core\Repositories\SubscribersListRepository
*/
@ -52,8 +53,7 @@ class CustomerController extends Controller
CustomerRepository $customerRepository,
ProductReviewRepository $productReviewRepository,
SubscribersListRepository $subscriptionRepository
)
{
) {
$this->middleware('customer');
$this->_config = request('_config');
@ -66,7 +66,7 @@ class CustomerController extends Controller
}
/**
* Taking the customer to profile details page
* Taking the customer to profile details page.
*
* @return \Illuminate\View\View
*/
@ -100,9 +100,9 @@ class CustomerController extends Controller
$id = auth()->guard('customer')->user()->id;
$this->validate(request(), [
'first_name' => 'required|string',
'last_name' => 'required|string',
'gender' => 'required',
'first_name' => ['required', new AlphaNumericSpace],
'last_name' => ['required', new AlphaNumericSpace],
'gender' => 'required|in:Other,Male,Female',
'date_of_birth' => 'date|before:today',
'email' => 'email|unique:customers,email,' . $id,
'password' => 'confirmed|min:6|required_with:oldpassword',
@ -113,13 +113,13 @@ class CustomerController extends Controller
$data = collect(request()->input())->except('_token')->toArray();
if (isset ($data['date_of_birth']) && $data['date_of_birth'] == "") {
if (isset($data['date_of_birth']) && $data['date_of_birth'] == "") {
unset($data['date_of_birth']);
}
$data['subscribed_to_news_letter'] = isset($data['subscribed_to_news_letter']) ? 1 : 0;
if (isset ($data['oldpassword'])) {
if (isset($data['oldpassword'])) {
if ($data['oldpassword'] != "" || $data['oldpassword'] != null) {
if (Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
$isPasswordChanged = true;
@ -166,7 +166,8 @@ class CustomerController extends Controller
'email' => $data['email'],
'token' => $token,
]));
} catch (\Exception $e) { }
} catch (\Exception $e) {
}
}
} else {
$subscription = $this->subscriptionRepository->findOneWhere(['email' => $data['email']]);