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

101 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Support\Facades\Event;
use Cookie;
class SessionController extends Controller
{
/**
2019-07-01 11:33:36 +00:00
* 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 Repository instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('customer')->except(['show','create']);
2019-07-01 11:33:36 +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
*/
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');
} else {
return view($this->_config['view']);
}
}
2019-07-01 11:33:36 +00:00
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
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',
]);
2019-01-15 11:54:41 +00:00
if (! auth()->guard('customer')->attempt(request(['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));
2019-07-01 11:33:36 +00:00
Cookie::queue(Cookie::make('email-for-resend', request('email'), 1));
auth()->guard('customer')->logout();
return redirect()->back();
}
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'));
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']);
}
}