sarga/packages/Webkul/Customer/src/Http/Controllers/SessionController.php

99 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\Customer\Http\Controllers;
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;
class SessionController extends Controller
{
/**
* Contains route related configuration.
*
2019-07-01 11:33:36 +00:00
* @var array
*/
protected $_config;
2019-07-01 11:33:36 +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
*/
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
*/
public function show()
{
return auth()->guard('customer')->check()
? redirect()->route('customer.profile.index')
: view($this->_config['view']);
}
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)
{
2021-06-25 13:54:55 +00:00
$request->validated();
2021-06-25 13:54:55 +00:00
if (! auth()->guard('customer')->attempt($request->only(['email', 'password']))) {
session()->flash('error', trans('shop::app.customer.login-form.invalid-creds'));
return redirect()->back();
}
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'));
return redirect()->back();
}
2019-01-15 11:54:41 +00:00
if (auth()->guard('customer')->user()->is_verified == 0) {
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));
auth()->guard('customer')->logout();
return redirect()->back();
}
/**
* Event passed to prepare cart after login.
*/
2021-06-25 13:54:55 +00:00
Event::dispatch('customer.after.login', $request->get('email'));
return redirect()->intended(route($this->_config['redirect']));
}
2019-07-01 11:33:36 +00:00
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
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
return redirect()->route($this->_config['redirect']);
}
2021-06-25 11:36:47 +00:00
}