File: D:/HostingSpaces/SBogers84/zuiderbos.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 Komma\Kms\Core\ValuesController;
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 ValuesController {
/**
* 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'))->orWhere('username', 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 = false;
// Login
if (Auth::user()->attempt(['email' => Input::get('email'), 'password' => Input::get('password')])) $login = true;
if (Auth::user()->attempt(['username' => Input::get('email'), 'password' => Input::get('password')])) $login = true;
if($login)
{
$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('/kms');
}
}