File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Auth/Kms/LoginController.php
<?php
namespace App\Komma\Auth\Kms;
use App\Komma\Base\Controller;
use App\Komma\Kms\ActionLog\ActionLogService;
use App\Komma\Users\Models\KmsUser;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
final class LoginController 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.
|
*/
/**
* @var int $maxAttempts How many times you may try to login with wrong credentials before being locked out
*/
protected $maxAttempts = 5;
/**
* @var int $decayMinutes How long it takes before you can login again after being locked out in minutes
*/
protected $decayMinutes = 1;
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/kms';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
public function showLoginForm()
{
return view('kms.auth.login');
}
/**
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
* @return bool
* @throws \Exception
*/
protected function attemptLogin(Request $request)
{
$valid = $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
if($valid) {
ActionLogService::Log('Logged in successfully at the kms end', null, $this->guard()->user());
} else {
ActionLogService::Log('Failed to login (wrong credentials or permissions)', [
'email' => $request->input('email'),
'password' => Hash::make($request->input('password')),
'ip' => $request->ip(),
], $this->guard()->user());
}
return $valid;
}
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
return $request->only($this->username(), KmsUser::PASSWORD_COLUMN_NAME);
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @throws \Exception
*/
public function logout(Request $request)
{
ActionLogService::Log('Logged out from kms', null, $this->guard()->user());
$this->guard()->logout();
$request->session()->invalidate();
return redirect('/kms');
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('kms');
}
}