This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/app/Http/Controllers/Auth/LoginController.php
2017-08-03 16:35:36 +10:00

83 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
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.
|
*/
use AuthenticatesUsers {
attemptLogin as attemptLoginAtAuthenticatesUsers;
}
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Returns field name to use at login.
*
* @return string
*/
public function username()
{
return config('auth.providers.users.field','email');
}
/**
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptLogin(Request $request)
{
if ($this->username() === 'email')
return $this->attemptLoginAtAuthenticatesUsers($request);
if ( ! $this->attemptLoginAtAuthenticatesUsers($request)) {
return $this->attempLoginUsingUsernameAsAnEmail($request);
}
return false;
}
/**
* Attempt to log the user into application using username as an email.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attempLoginUsingUsernameAsAnEmail(Request $request)
{
return $this->guard()->attempt(
['email' => $request->input('username'), 'password' => $request->input('password')],
$request->has('remember'));
}
}