2018-07-24 14:33:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Customer\Http\Controllers;
|
|
|
|
|
|
2018-11-27 10:55:23 +00:00
|
|
|
use Cookie;
|
2021-06-25 11:36:47 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2021-06-25 13:54:55 +00:00
|
|
|
use Webkul\Customer\Http\Requests\CustomerLoginRequest;
|
2018-10-27 11:13:57 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
class SessionController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
2021-06-25 11:55:40 +00:00
|
|
|
* Contains route related configuration.
|
2018-07-24 14:33:49 +00:00
|
|
|
*
|
2019-07-01 11:33:36 +00:00
|
|
|
* @var array
|
2018-07-24 14:33:49 +00:00
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
/**
|
2021-06-25 11:55:40 +00:00
|
|
|
* Create a new controller instance.
|
2019-07-01 11:33:36 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
2021-06-25 11:36:47 +00:00
|
|
|
*/
|
2018-07-24 14:33:49 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
/**
|
|
|
|
|
* Display the resource.
|
|
|
|
|
*
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2019-07-01 11:33:36 +00:00
|
|
|
*/
|
2018-07-24 14:33:49 +00:00
|
|
|
public function show()
|
|
|
|
|
{
|
2021-06-25 11:55:40 +00:00
|
|
|
return auth()->guard('customer')->check()
|
|
|
|
|
? redirect()->route('customer.profile.index')
|
|
|
|
|
: view($this->_config['view']);
|
2018-07-24 14:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
2021-06-25 13:54:55 +00:00
|
|
|
* @param \Webkul\Customer\Http\Requests\CustomerLoginRequest $request
|
2019-07-01 11:33:36 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2021-06-25 13:54:55 +00:00
|
|
|
public function create(CustomerLoginRequest $request)
|
2018-07-24 14:33:49 +00:00
|
|
|
{
|
2021-06-25 13:54:55 +00:00
|
|
|
$request->validated();
|
2018-07-24 14:33:49 +00:00
|
|
|
|
2021-06-25 13:54:55 +00:00
|
|
|
if (! auth()->guard('customer')->attempt($request->only(['email', 'password']))) {
|
2018-11-27 10:55:23 +00:00
|
|
|
session()->flash('error', trans('shop::app.customer.login-form.invalid-creds'));
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 01:04:46 +00:00
|
|
|
if (auth()->guard('customer')->user()->status == 0) {
|
|
|
|
|
auth()->guard('customer')->logout();
|
|
|
|
|
|
2019-06-13 01:07:16 +00:00
|
|
|
session()->flash('warning', trans('shop::app.customer.login-form.not-activated'));
|
|
|
|
|
|
2019-06-13 01:04:46 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if (auth()->guard('customer')->user()->is_verified == 0) {
|
2018-11-27 10:55:23 +00:00
|
|
|
session()->flash('info', trans('shop::app.customer.login-form.verify-first'));
|
|
|
|
|
|
|
|
|
|
Cookie::queue(Cookie::make('enable-resend', 'true', 1));
|
|
|
|
|
|
2021-06-25 13:54:55 +00:00
|
|
|
Cookie::queue(Cookie::make('email-for-resend', $request->get('email'), 1));
|
2018-11-27 10:55:23 +00:00
|
|
|
|
|
|
|
|
auth()->guard('customer')->logout();
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
2018-07-24 14:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-25 11:55:40 +00:00
|
|
|
/**
|
|
|
|
|
* Event passed to prepare cart after login.
|
|
|
|
|
*/
|
2021-06-25 13:54:55 +00:00
|
|
|
Event::dispatch('customer.after.login', $request->get('email'));
|
2018-09-13 11:06:17 +00:00
|
|
|
|
|
|
|
|
return redirect()->intended(route($this->_config['redirect']));
|
2018-07-24 14:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-07-24 14:33:49 +00:00
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
|
|
|
|
auth()->guard('customer')->logout();
|
2018-09-15 08:09:56 +00:00
|
|
|
|
2019-12-24 14:01:13 +00:00
|
|
|
Event::dispatch('customer.after.logout', $id);
|
2018-09-15 08:09:56 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
2021-06-25 11:36:47 +00:00
|
|
|
}
|