2018-07-24 14:33:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Customer\Http\Controllers;
|
|
|
|
|
|
2018-09-13 11:06:17 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2018-11-27 10:55:23 +00:00
|
|
|
use Cookie;
|
2018-10-27 11:13:57 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
class SessionController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
2019-07-01 11:33:36 +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
|
|
|
/**
|
|
|
|
|
* Create a new Repository instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-07-24 14:33:49 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2018-08-31 06:03:11 +00:00
|
|
|
$this->middleware('customer')->except(['show','create']);
|
2019-07-01 11:33:36 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
$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()
|
|
|
|
|
{
|
2019-01-15 11:54:41 +00:00
|
|
|
if (auth()->guard('customer')->check()) {
|
2019-07-23 06:34:09 +00:00
|
|
|
return redirect()->route('customer.profile.index');
|
2018-08-31 06:03:11 +00:00
|
|
|
} else {
|
|
|
|
|
return 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.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
2018-07-24 14:33:49 +00:00
|
|
|
{
|
2019-07-01 11:33:36 +00:00
|
|
|
$this->validate(request(), [
|
2020-02-19 13:48:54 +00:00
|
|
|
'email' => 'required|email',
|
2020-03-04 06:32:53 +00:00
|
|
|
'password' => 'required',
|
2018-07-24 14:33:49 +00:00
|
|
|
]);
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if (! auth()->guard('customer')->attempt(request(['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));
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
Cookie::queue(Cookie::make('email-for-resend', request('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
|
|
|
}
|
|
|
|
|
|
2018-09-11 11:19:40 +00:00
|
|
|
//Event passed to prepare cart after login
|
2019-12-24 14:01:13 +00:00
|
|
|
Event::dispatch('customer.after.login', request('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']);
|
|
|
|
|
}
|
2018-08-31 06:03:11 +00:00
|
|
|
}
|