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/SBogers93/fitale.nl/workbench/komma/kms/src/Komma/Kms/Users/AuthController.php
<?php

namespace Komma\Kms\Users;

use Auth;
use Input;
use Komma\Kms\Core\ThemeController;
use Redirect;
use View;
use Carbon\Carbon;
use Config;

/**
 * Short description for the file.
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

class AuthController extends ThemeController {

    /**
     * Show the login form.
     *
     * @return \Illuminate\View\View
     */
    public function login()
    {
        return View::make('kms::auth.login');
    }

    /**
     * Handle the response from the login form.
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function processLogin()
    {
        if(! $user = User::where('email', Input::get('email'))->first())
        {
            return Redirect::back()
                ->withInput()
                ->withErrors([
                    'message' => 'It looks like that the e-mail address or password is not the right one. Try again?'
                ]);
        }

        $user->failed_login_attempts++;
        if($user->failed_login_attempts >= Config::get('kms::main.maxLoginAttempts'))
        {
            if (Carbon::now()->diffInSeconds($user['last_login_attempt']) < Config::get('kms::main.failedLoginWaitingTime'))
            {
                return Redirect::back()
                    ->withInput()
                    ->withErrors([
                        'message' => 'Too many invalid login attempts, please wait 1 hour before trying again.'
                    ]);
            }
            $user->failed_login_attempts = 0;
        }

        // Login
        if (Auth::user()->attempt(['email' => Input::get('email'), 'password' => Input::get('password')]))
        {
            $user->failed_login_attempts = 0;
            $user->save();
            return Redirect::intended('/kms')->withSuccess('Logged in');
        }

        $user->last_login_attempt = Carbon::now();
        $user->save();

        return Redirect::back()
            ->withInput()
            ->withErrors([
                'message' => 'It looks like that the e-mail address or password is not the right one. Try again?'
            ]);
    }

    /**
     * Logout and redirect to the homepage.
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function logout()
    {
        Auth::user()->logout();
        return Redirect::to('/');
    }

}