2018-07-24 14:33:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Customer\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Routing\Controller;
|
2018-08-22 09:46:27 +00:00
|
|
|
use Webkul\Customer\Repositories\CustomerRepository;
|
2018-07-24 14:33:49 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-08-23 13:11:56 +00:00
|
|
|
* Registration controller
|
2018-07-24 14:33:49 +00:00
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class RegistrationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
2018-08-23 13:11:56 +00:00
|
|
|
protected $customer;
|
2018-07-24 14:33:49 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
|
|
|
|
|
public function __construct(CustomerRepository $customer)
|
2018-07-24 14:33:49 +00:00
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
2018-08-23 13:11:56 +00:00
|
|
|
$this->customer = $customer;
|
2018-07-24 14:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-22 08:31:18 +00:00
|
|
|
* Opens up the
|
|
|
|
|
* user's sign up
|
|
|
|
|
* form.
|
|
|
|
|
*
|
2018-07-24 14:33:49 +00:00
|
|
|
* @return view
|
|
|
|
|
*/
|
|
|
|
|
public function show()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-22 08:31:18 +00:00
|
|
|
* Method to store
|
|
|
|
|
* user's sign up
|
|
|
|
|
* form data to DB
|
|
|
|
|
*
|
|
|
|
|
* @return Mixed
|
2018-07-24 14:33:49 +00:00
|
|
|
*/
|
|
|
|
|
public function create(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'first_name' => 'string|required',
|
|
|
|
|
'last_name' => 'string|required',
|
|
|
|
|
'email' => 'email|required',
|
2018-09-22 08:31:18 +00:00
|
|
|
'password' => 'confirmed|min:6|required',
|
2018-10-23 11:46:00 +00:00
|
|
|
'agreement' => 'required'
|
2018-07-24 14:33:49 +00:00
|
|
|
]);
|
2018-08-22 09:46:27 +00:00
|
|
|
|
2018-09-22 08:31:18 +00:00
|
|
|
$data = request()->input();
|
|
|
|
|
|
|
|
|
|
$data['password'] = bcrypt($data['password']);
|
|
|
|
|
|
2018-10-23 11:46:00 +00:00
|
|
|
$data['channel_id'] = core()->getCurrentChannel()->id;
|
|
|
|
|
|
2018-09-22 08:31:18 +00:00
|
|
|
if ($this->customer->create($data)) {
|
2018-08-22 09:46:27 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
session()->flash('success', 'Account created successfully.');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-08-22 09:46:27 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
} else {
|
|
|
|
|
session()->flash('error', 'Cannot Create Your Account.');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|