我想在laravel中实现自己的身份验证系统,而不是默认的,所以我正在通过THIS教程。它使用laravel-4,所以显然有些代码会改变。下面有当用户进行认证的代码片段,见下图:laravel中的Auth类如何知道哪个表比较数据?还有哪些字段需要检查?
// app/controllers/HomeController.php<
public function doLogin() {
// validate the info, create rules for the inputs
$rules = array(
'email' => 'required|email', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
// create our user data for the authentication
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
echo 'SUCCESS!';
} else {
// validation not successful, send back to form
return Redirect::to('login');
}
}
}
我不太明白下面的一行代码:
if (Auth::attempt($userdata)) {
怎样的验证类知道哪个表寻找和比较数据?另外它如何知道哪些字段与之比较?这有点令人困惑。有人可以解释一下吗?
INTRO auth class对我来说很了解Auth类是如何工作的,但我仍然没有完全回答上述问题。