Akaunting/app/Http/Controllers/Auth/Login.php

108 lines
2.5 KiB
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class Login extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
/*public function __construct()
{
$this->middleware('guest')->except('logout');
}*/
public function __construct()
{
$this->middleware('guest', ['except' => 'destroy']);
}
public function create()
{
return view('auth.login.create');
}
public function store()
{
2017-10-07 20:52:34 +00:00
// Attempt to login
2018-11-04 07:08:08 +00:00
if (!auth()->attempt(request(['email', 'password']), request('remember', false))) {
2017-10-07 20:52:34 +00:00
flash(trans('auth.failed'))->error();
2017-09-14 19:21:00 +00:00
return back();
}
2017-10-07 20:52:34 +00:00
// Get user object
$user = auth()->user();
// Check if user is enabled
if (!$user->enabled) {
2018-06-09 12:37:28 +00:00
$this->logout();
2017-10-07 20:52:34 +00:00
flash(trans('auth.disabled'))->error();
return redirect('auth/login');
}
// Check if is customer
if ($user->customer) {
2018-03-06 14:49:27 +00:00
$path = session('url.intended', 'customers');
// Path must start with 'customers' prefix
2018-03-06 14:55:05 +00:00
if (!str_contains($path, 'customers')) {
2018-03-06 14:49:27 +00:00
$path = 'customers';
}
return redirect($path);
2017-09-14 19:21:00 +00:00
}
2018-10-23 15:47:55 +00:00
// Check wizard
if (!setting('general.wizard', false)) {
return redirect('wizard');
}
2017-09-14 19:21:00 +00:00
return redirect('/');
}
public function destroy()
{
2018-06-09 12:37:28 +00:00
$this->logout();
2017-09-14 19:21:00 +00:00
return redirect('auth/login');
}
2018-06-09 12:37:28 +00:00
public function logout()
{
auth()->logout();
// Session destroy is required if stored in database
if (env('SESSION_DRIVER') == 'database') {
$request = app('Illuminate\Http\Request');
$request->session()->getHandler()->destroy($request->session()->getId());
}
}
2017-09-14 19:21:00 +00:00
}