2018-06-20 05:06:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\User\Http\Controllers;
|
|
|
|
|
|
2018-08-31 06:03:11 +00:00
|
|
|
use Auth;
|
2018-06-20 05:06:27 +00:00
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
class SessionController extends Controller
|
2018-06-20 05:06:27 +00:00
|
|
|
{
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2018-06-20 05:06:27 +00:00
|
|
|
protected $_config;
|
|
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-06-20 05:06:27 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2018-08-31 06:03:11 +00:00
|
|
|
$this->middleware('admin')->except(['create','store']);
|
|
|
|
|
|
2018-06-20 05:06:27 +00:00
|
|
|
$this->_config = request('_config');
|
|
|
|
|
|
|
|
|
|
$this->middleware('guest', ['except' => 'destroy']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
2019-10-18 13:13:38 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-06-20 05:06:27 +00:00
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
2018-08-31 06:03:11 +00:00
|
|
|
if (auth()->guard('admin')->check()) {
|
|
|
|
|
return redirect()->route('admin.dashboard.index');
|
|
|
|
|
} else {
|
2019-02-11 10:05:02 +00:00
|
|
|
if (strpos(url()->previous(), 'admin') !== false) {
|
|
|
|
|
$intendedUrl = url()->previous();
|
|
|
|
|
} else {
|
|
|
|
|
$intendedUrl = route('admin.dashboard.index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session()->put('url.intended', $intendedUrl);
|
|
|
|
|
|
2018-08-31 06:03:11 +00:00
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
2018-07-05 07:58:26 +00:00
|
|
|
$this->validate(request(), [
|
2020-02-20 07:14:00 +00:00
|
|
|
'email' => 'required|email',
|
2020-03-04 06:32:53 +00:00
|
|
|
'password' => 'required',
|
2018-07-05 07:58:26 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$remember = request('remember');
|
2018-12-18 10:44:21 +00:00
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if (! auth()->guard('admin')->attempt(request(['email', 'password']), $remember)) {
|
2019-02-13 12:12:07 +00:00
|
|
|
session()->flash('error', trans('admin::app.users.users.login-error'));
|
2018-07-05 07:58:26 +00:00
|
|
|
|
2019-02-14 12:50:04 +00:00
|
|
|
return redirect()->back();
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-18 10:44:21 +00:00
|
|
|
if (auth()->guard('admin')->user()->status == 0) {
|
2019-02-13 12:12:07 +00:00
|
|
|
session()->flash('warning', trans('admin::app.users.users.activate-warning'));
|
2018-12-18 10:44:21 +00:00
|
|
|
|
|
|
|
|
auth()->guard('admin')->logout();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('admin.session.create');
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 06:03:11 +00:00
|
|
|
return redirect()->intended(route($this->_config['redirect']));
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
|
|
|
|
auth()->guard('admin')->logout();
|
|
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
2019-02-14 12:50:04 +00:00
|
|
|
}
|