2015-08-25 149 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中的存储基本上存储在会话中。 –