File: D:/HostingSpaces/SBogers10/boldt.komma.pro/app/Komma/Auth/SiteLoginController.php
<?php
namespace App\Komma\Auth;
use App\Komma\Base\Controller;
use App\Komma\Kms\ActionLog\ActionLogService;
use App\Komma\Users\Models\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
final class SiteLoginController 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 = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
parent::__construct();
}
public function showLoginForm()
{
return view('site.templates.auth.login', ['links' => $this->links, 'languageMenu' => ['nl' => '/nl/inloggen', 'en' => '/en/login'] ]);
}
/**
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptLogin(Request $request)
{
$valid = $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
if($valid) {
ActionLogService::Log('Logged in successfully at the front end');
} else {
ActionLogService::Log('Failed to login at the frontend (wrong credentials or permissions)', [
'email' => $request->input('email'),
'password' => \Hash::make($request->input('password')),
'ip' => $request->ip(),
]);
}
return $valid;
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return User::USERNAME_COLUMN_NAME;
}
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
return array_merge( $request->only($this->username(), User::PASSWORD_COLUMN_NAME), ['approved' => 1]);
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout()
{
ActionLogService::Log('Logged out at the frontend');
$this->guard()->logout();
request()->session()->invalidate();
return redirect(url()->previous());
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('site');
}
}