久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel框架用戶登陸身份驗證實現(xiàn)方法詳解

這篇文章主要介紹了Laravel框架用戶登陸身份驗證實現(xiàn)方法,結(jié)合實例形式分析了Laravel框架用戶登陸驗證的原理、實現(xiàn)方法與相關(guān)注意事項,需要的朋友可以參考下

本文實例講述了Laravel框架用戶登陸身份驗證實現(xiàn)方法。分享給大家供大家參考,具體如下:

laravel中檢測用戶是否登錄,有以下的代碼:

if ( !Auth::guest() )
{
  return Redirect::to('/dashboard');
}

Auth::guest是如何調(diào)用的呢?

laravel用了Facade模式,相關(guān)門面類在laravel/framework/src/Illuminate/Support/Facades文件夾定義的,看下Auth類的定義:

class Auth extends Facade {
  /**
   * Get the registered name of the component.
   *
   * @return string
   */
  protected static function getFacadeAccessor() { return 'auth'; }
}

laravel框架中,F(xiàn)acade模式使用反射,相關(guān)方法其實調(diào)用app['auth']中的方法,app['auth']是什么時候創(chuàng)建的呢,

AuthServiceProvider::register方法會注冊:

$this->app->bindShared('auth', function($app)
{
  // Once the authentication service has actually been requested by the developer
  // we will set a variable in the application indicating such. This helps us
  // know that we need to set any queued cookies in the after event later.
  $app['auth.loaded'] = true;
  return new AuthManager($app);
});

那為什么最終會調(diào)到哪里呢,看下堆棧:

Illuminate\Support\Facades\Auth::guest()
Illuminate\Support\Facades\Facade::__callStatic
Illuminate\Auth\AuthManager->guest()
Illuminate\Support\Manager->__call
public function __call($method, $parameters)
{
    return call_user_func_array(array($this->driver(), $method), $parameters);
}

看下driver的代碼:

public function driver($driver = null)
{
    $driver = $driver ?: $this->getDefaultDriver();
    // If the given driver has not been created before, we will create the instances
    // here and cache it so we can return it next time very quickly. If there is
    // already a driver created by this name, we'll just return that instance.
    if ( ! isset($this->drivers[$driver]))
    {
      $this->drivers[$driver] = $this->createDriver($driver);
    }
    return $this->drivers[$driver];
}

沒有會調(diào)用getDefaultDrive方法

/**
* Get the default authentication driver name.
*
* @return string
*/
public function getDefaultDriver()
{
    return $this->app['config']['auth.driver'];
}

最終調(diào)用的是配置文件中配置的driver,如果配的是

'driver' => 'eloquent'

則調(diào)用的是

public function createEloquentDriver()
{
    $provider = $this->createEloquentProvider();
    return new Guard($provider, $this->app['session.store']);
}

所以Auth::guest最終調(diào)用的是Guard::guest方法

這里的邏輯先從session中取用戶信息,奇怪的是session里只保存的是用戶ID,然后拿這個ID來從數(shù)據(jù)庫中取用戶信息

public function user()
{
    if ($this->loggedOut) return;
    // If we have already retrieved the user for the current request we can just
    // return it back immediately. We do not want to pull the user data every
    // request into the method because that would tremendously slow an app.
    if ( ! is_null($this->user))
    {
      return $this->user;
    }
    $id = $this->session->get($this->getName());
    // First we will try to load the user using the identifier in the session if
    // one exists. Otherwise we will check for a "remember me" cookie in this
    // request, and if one exists, attempt to retrieve the user using that.
    $user = null;
    if ( ! is_null($id))
    {
      //provider為EloquentUserProvider
     $user = $this->provider->retrieveByID($id);
    }
    // If the user is null, but we decrypt a "recaller" cookie we can attempt to
    // pull the user data on that cookie which serves as a remember cookie on
    // the application. Once we have a user we can return it to the caller.
    $recaller = $this->getRecaller();
    if (is_null($user) && ! is_null($recaller))
    {
      $user = $this->getUserByRecaller($recaller);
    }
    return $this->user = $user;
}

更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。

【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

這篇文章主要介紹了Laravel框架+Blob實現(xiàn)的多圖上傳功能,結(jié)合實例形式詳細(xì)分析了Laravel框架+Blob進行多張圖片上傳操作的前端提交與后臺處理相關(guān)操作技巧,需要的朋友可以參考下
Laravel作為在國內(nèi)國外都頗為流行的PHP框架,風(fēng)格優(yōu)雅,其擁有自己的一些特點。下面這篇文章主要給大家介紹了關(guān)于Laravel框架中composer自動加載實現(xiàn)的相關(guān)資料,文中通過示例代碼介紹
Blade 是 laravel 提供的一個簡單強大的模板引擎。下面這篇文章主要給大家介紹了關(guān)于Laravel框架之blade模板新手的入門教程以及一些使用的小技巧,文中通過示例代碼介紹的非常詳細(xì),需
Blade 允許你自定義命令,你可以使用 directive 方法注冊命令。下面這篇文章主要給大家總結(jié)介紹了關(guān)于Laravel框架中自定義模板指令的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要
Laravel以其簡潔、優(yōu)雅的特性贏得了大家的廣泛關(guān)注,無論是專家還是新手,在開發(fā)PHP項目的時候,都會第一時間的想到Laravel。本文我們將討論為什么Laravel會成為最成功的PHP框架
這篇文章主要介紹了Laravel框架實現(xiàn)redis集群的方法,簡單分析了Laravel框架redis數(shù)據(jù)庫集群功能設(shè)置步驟、相關(guān)操作技巧與注意事項,需要的朋友可以參考下
主站蜘蛛池模板: 久久小视频 | 亚洲成人网在线播放 | 欧美成人a | 99亚洲国产精品 | 日韩在线大片 | 国产精品免费av | 色婷婷亚洲一区二区三区 | 国产jizz女人多喷水99 | 天天搞天天操 | 日韩精品一区二区不卡 | 国产精品久久国产精品 | 在线一级片| 美日韩精品 | 国产精品a久久久久 | 国产精品国产成人国产三级 | 黄色毛片免费看 | 伊人无码高清 | 久久久久国产 | 久久久精品影院 | 久久99精品久久久久久噜噜 | 99久久精品免费 | 先锋资源吧 | 久久亚| 能看的av | 久久爱综合 | 精品久久久久久久久久久久久久 | 视频在线观看一区 | 自拍偷拍中文字幕 | 91九色麻豆 | 国产在线播放av | 欧洲一区二区三区 | 亚洲免费在线 | 中文字幕高清 | 日韩免费1区二区电影 | 国产精品久久久久久福利一牛影视 | 久久国产日韩 | 欧美精品成人一区二区三区四区 | 在线国产一区二区 | h片在线观看网站 | 亚洲黄色一级毛片 | 久久久久一区二区三区 |