HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/ReturnIndustries/return-industries.nl/app/Komma/Auth/LoginController.php
<?php

namespace App\Komma\Auth;

use App\Komma\Base\Controller;
use App\Komma\Kms\ActionLog\ActionLogService;
use App\Komma\Users\Models\SiteUser;
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 = '/';



    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
        $this->redirectTo = url()->previous();
    }

    public function showLoginForm()
    {
        return view('site.templates.auth.login', ['links' => $this->links]);
    }

    /**
     * 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 site end', null, $this->guard()->user());
        } 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(),
            ], $this->guard()->user());
        }

        return $valid;
    }

    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        return SiteUser::USERNAME_COLUMN_NAME;
    }

    /**
     * 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(), SiteUser::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 at the frontend', null, $this->guard()->user());
        $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');
    }
}