2015-08-25 148 views
2

我明白auth函數允許用戶登錄等,但我想確認背景中究竟發生了什麼。Laravel 5 Auth - 究竟是什麼?

我的猜測是,它只是一個保存登錄信息的cookie,對嗎?

或者它只是存儲remember_token,然後自動將它與存儲在users表中的內容進行比較?

所以,如果我想創建一個帳戶編輯頁面。我需要做什麼比較auth id和電子郵件匹配的用戶表ID嗎?還是它自動處理所有這些?

+1

你可以看看位於'vendor/laravel/framework/src/Illuminate/Auth'中的'Auth'軟件包文件,特別是'Guard.php'文件,以瞭解它在做什麼以及如何做。 – Bogdan

回答

1

Laravel Auth只是它的類,其中所有的認證方法或函數都是在laravel框外編寫的,因此您不需要編寫所有與用戶登錄有關的函數。例如,我們只需簡單地檢查用戶使用 Auth :: check();

但laravel權威性類,他們爲我們傳遞參數嘗試的方法。這裏也laravel內置功能的登錄嘗試以同樣的方式寫成這樣

public function check() 
    { 
     return !is_null($this->user()); 
    } 

public function attempt(array $credentials = [], $remember = false, $login = true) 
    { 
     $this->fireAttemptEvent($credentials, $remember, $login); 

     $this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials); 

     // If an implementation of UserInterface was returned, we'll ask the provider 
     // to validate the user against the given credentials, and if they are in 
     // fact valid we'll log the users into the application and return true. 
     if ($this->hasValidCredentials($user, $credentials)) { 
      if ($login) { 
       $this->login($user, $remember); 
      } 

      return true; 
     } 

     return false; 
    } 

在這裏,你傳遞所有憑證並記住密碼和所有

+0

我明白,但如果我做一些像Auth :: User() - > id那麼安全嗎? Auth用戶ID是否存儲在cookie中?在這種情況下,這不會變化嗎? – user1157885

+0

我認爲它的安全。我不認爲它在cookie.its中的存儲基本上存儲在會話中。 –