<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
trait AuthenticatesUsers
{
use RedirectsUsers, ThrottlesLogins;
/**
* Show the application's login form.
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm()
{
return view('auth.login');
}
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
*/
public function login(Request $request)
{
//得到用戶表單提交過來內(nèi)容,進行驗證__zk
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
//如果正確返回數(shù)組__zk
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
/**
* Validate the user login request.
*驗證用戶登錄__zk
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
/**
* Attempt to log the user into the application.
*登錄賬號密碼正確 返回1__zk
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
}
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
//增加附加權限__zk
// return $request->only($this->username(), 'password');
$credentials = $request->only($this->username(), 'password'); // or add another item here if it's from the request
$credentials['qx'] = 1;
$credentials['is_del'] = 0;
return $credentials;
}
/**
* Send the response after the user was authenticated.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendLoginResponse(Request $request)
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());
}
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
//
}
/**
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return 'email';
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect('/login');
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard();
}
}
laravel自帶登錄配置文件
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門聚蝶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人藻治,你說我怎么就攤上這事碘勉。” “怎么了桩卵?”我有些...
- 文/不壞的土叔 我叫張陵验靡,是天一觀的道長倍宾。 經(jīng)常有香客問我,道長胜嗓,這世上最難降的妖魔是什么高职? 我笑而不...
- 文/花漫 我一把揭開白布排作。 她就那樣靜靜地躺著牵啦,像睡著了一般。 火紅的嫁衣襯著肌膚如雪妄痪。 梳的紋絲不亂的頭發(fā)上哈雏,一...
- 文/蒼蘭香墨 我猛地睜開眼泪酱,長吁一口氣:“原來是場噩夢啊……” “哼派殷!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起墓阀,我...
- 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響种蝶,放射性物質(zhì)發(fā)生泄漏契耿。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一螃征、第九天 我趴在偏房一處隱蔽的房頂上張望搪桂。 院中可真熱鬧,春花似錦盯滚、人聲如沸踢械。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽内列。三九已至,卻和暖如春背率,著一層夾襖步出監(jiān)牢的瞬間话瞧,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 開啟郵箱服務 要使用郵箱服務就必須開啟郵箱的 POP3 服務和 SMTP 服務都许,本教程演示 QQ郵箱的配置 登錄你...
- 命令優(yōu)化 本文的目的是來弄清楚一些優(yōu)化命令在 Laravel 5.1 和之前版本之間的差別. 在 15年6月發(fā)布的...
- .env 文件下的一些常用語句 APP_ENV=local(當前環(huán)境)APP_DEBUG=true(是否顯示調(diào)試信...
- 問題描述:若在config目錄下添加config_dev.php , config_test.php , conf...