laravel自帶登錄配置文件

<?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();
    }
}
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市塘慕,隨后出現(xiàn)的幾起案子戚宦,更是在濱河造成了極大的恐慌泵喘,老刑警劉巖重荠,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拄丰,死亡現(xiàn)場離奇詭異蝇棉,居然都是意外死亡,警方通過查閱死者的電腦和手機澜倦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門聚蝶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人藻治,你說我怎么就攤上這事碘勉。” “怎么了桩卵?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵验靡,是天一觀的道長倍宾。 經(jīng)常有香客問我,道長胜嗓,這世上最難降的妖魔是什么高职? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮辞州,結果婚禮上怔锌,老公的妹妹穿的比我還像新娘。我一直安慰自己孙技,他們只是感情好,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布排作。 她就那樣靜靜地躺著牵啦,像睡著了一般。 火紅的嫁衣襯著肌膚如雪妄痪。 梳的紋絲不亂的頭發(fā)上哈雏,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天,我揣著相機與錄音衫生,去河邊找鬼裳瘪。 笑死,一個胖子當著我的面吹牛罪针,可吹牛的內(nèi)容都是我干的彭羹。 我是一名探鬼主播,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼泪酱,長吁一口氣:“原來是場噩夢啊……” “哼派殷!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起墓阀,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤毡惜,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后斯撮,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體经伙,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年勿锅,在試婚紗的時候發(fā)現(xiàn)自己被綠了帕膜。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡溢十,死狀恐怖泳叠,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情茶宵,我是刑警寧澤危纫,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響种蝶,放射性物質(zhì)發(fā)生泄漏契耿。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一螃征、第九天 我趴在偏房一處隱蔽的房頂上張望搪桂。 院中可真熱鬧,春花似錦盯滚、人聲如沸踢械。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽内列。三九已至,卻和暖如春背率,著一層夾襖步出監(jiān)牢的瞬間话瞧,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工寝姿, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留交排,地道東北人。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓饵筑,卻偏偏與公主長得像埃篓,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子根资,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容