parent
42dca55245
commit
5784560c6c
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\API\Http\Controllers\Shop\SessionController;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
|
||||
class Customers extends SessionController
|
||||
{
|
||||
/**
|
||||
* Method to store user's sign up form data to DB.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'first_name' => 'required|string',
|
||||
'last_name' => 'required|string',
|
||||
'phone' => 'required|digits:8|unique:customers,phone',
|
||||
'password' => 'required|min:6',
|
||||
'gender' => 'in:Male,Female'
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'first_name' => $request->get('first_name'),
|
||||
'last_name' => $request->get('last_name'),
|
||||
'phone' => $request->get('phone'),
|
||||
'password' => bcrypt($request->get('password')),
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'is_verified' => 1,
|
||||
'gender' => $request->get('gender'),
|
||||
'customer_group_id' => $this->customerGroupRepository->findOneWhere(['code' => 'general'])->id
|
||||
];
|
||||
|
||||
Event::dispatch('customer.registration.before');
|
||||
|
||||
$customer = $this->customerRepository->create($data);
|
||||
|
||||
Event::dispatch('customer.registration.after', $customer);
|
||||
|
||||
if (! $jwtToken = auth()->guard($this->guard)->attempt($request->only(['phone', 'password']))) {
|
||||
return response()->json([
|
||||
'error' => 'Invalid Email or Password',
|
||||
], 401);
|
||||
}
|
||||
|
||||
Event::dispatch('customer.after.login', $request->get('phone'));
|
||||
|
||||
return response()->json([
|
||||
'token' => $jwtToken,
|
||||
'message' => 'Logged in successfully.',
|
||||
'data' => new CustomerResource($customer),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to store user's sign up form data to DB.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'phone' => 'required|digits:8',
|
||||
'password' => 'required|min:6',
|
||||
]);
|
||||
|
||||
$jwtToken = null;
|
||||
|
||||
if (! $jwtToken = auth()->guard($this->guard)->attempt($request->only(['phone', 'password']))) {
|
||||
return response()->json([
|
||||
'error' => 'Invalid Email or Password',
|
||||
], 401);
|
||||
}
|
||||
|
||||
Event::dispatch('customer.after.login', $request->get('phone'));
|
||||
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
return response()->json([
|
||||
'token' => $jwtToken,
|
||||
'message' => 'Logged in successfully.',
|
||||
'data' => new CustomerResource($customer),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'gender' => 'in:Male,Female',
|
||||
'date_of_birth' => 'nullable|date|before:today',
|
||||
'email' => 'email|unique:customers,email,' . $customer->id,
|
||||
'phone' => 'digits:8|unique:customers,phone,' . $customer->id,
|
||||
'password' => 'min:6',
|
||||
]);
|
||||
|
||||
$data = request()->only('first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'password','phone');
|
||||
|
||||
if (! isset($data['password']) || ! $data['password']) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}
|
||||
|
||||
$updatedCustomer = $this->customerRepository->update($data, $customer->id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your account has been updated successfully.',
|
||||
'data' => new CustomerResource($updatedCustomer),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ use Sarga\API\Repositories\ProductRepository;
|
|||
use Sarga\Shop\Repositories\CategoryRepository;
|
||||
use Webkul\API\Http\Controllers\Shop\Controller;
|
||||
use Webkul\Marketplace\Repositories\SellerRepository;
|
||||
use Webkul\Product\Repositories\ProductFlatRepository;
|
||||
|
||||
class Vendors extends Controller
|
||||
{
|
||||
|
|
@ -45,6 +46,11 @@ class Vendors extends Controller
|
|||
}])
|
||||
->orderBy('position','asc')
|
||||
->get();
|
||||
if($vendor->main_categories->count()){
|
||||
foreach($vendor->main_categories as $category){
|
||||
$category->filters = app(ProductFlatRepository::class)->getProductsRelatedFilterableAttributes($category);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Sarga\API\Http\Controllers\Customers;
|
||||
use Sarga\API\Http\Controllers\Categories;
|
||||
use Sarga\API\Http\Controllers\Channels;
|
||||
use Sarga\API\Http\Controllers\IntegrationController;
|
||||
|
|
@ -47,4 +48,8 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
Route::put('upload',[IntegrationController::class,'bulk_upload']);
|
||||
Route::put('create',[IntegrationController::class,'create']);
|
||||
});
|
||||
|
||||
Route::post('customer/register', [Customers::class, 'register']);
|
||||
Route::post('customer/login', [Customers::class, 'login']);
|
||||
Route::put('customer/profile', [Customers::class, 'update']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue