55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Webkul\API\Http\Controllers\Customer;
|
||
|
|
|
||
|
|
use Webkul\API\Http\Controllers\Controller;
|
||
|
|
use Webkul\Customer\Repositories\CustomerRepository as Customer;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Http\Response;
|
||
|
|
use Illuminate\Support\Facades\Event;
|
||
|
|
use Validator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Registration controller for the APIs of Customer Registration
|
||
|
|
*
|
||
|
|
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||
|
|
*/
|
||
|
|
class RegistrationController extends Controller
|
||
|
|
{
|
||
|
|
protected $customer;
|
||
|
|
|
||
|
|
public function __construct(Customer $customer) {
|
||
|
|
$this->customer = $customer;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function create() {
|
||
|
|
$validator = Validator::make(request()->all(), [
|
||
|
|
'first_name' => 'string|required',
|
||
|
|
'last_name' => 'string|required',
|
||
|
|
'email' => 'email|required|unique:customers,email',
|
||
|
|
'password' => 'confirmed|min:6|required',
|
||
|
|
'agreement' => 'required'
|
||
|
|
]);
|
||
|
|
|
||
|
|
if ($validator->fails()) {
|
||
|
|
return response()->json($validator->messages(), 400);
|
||
|
|
}
|
||
|
|
|
||
|
|
$data = request()->all();
|
||
|
|
|
||
|
|
$data['password'] = bcrypt($data['password']);
|
||
|
|
|
||
|
|
$data['channel_id'] = core()->getCurrentChannel()->id;
|
||
|
|
|
||
|
|
$data['is_verified'] = 0;
|
||
|
|
|
||
|
|
$result = $this->customer->create($data);
|
||
|
|
|
||
|
|
if ($result) {
|
||
|
|
return response()->json(true, 200);
|
||
|
|
} else {
|
||
|
|
return response()->json(false, 200);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|