【发布时间】:2015-03-17 03:13:32
【问题描述】:
我正在使用内置 Auth::attempt 功能的 Laravel 来尝试为我的网站创建登录脚本。但是,Auth::attempt 总是返回 false。这个问题似乎与许多其他有类似问题的人相似,但是他们收到的答案对我的问题没有帮助/适用。我在 YouTube 上关注 Phpacademy 的教程,我的登录几乎是逐字记录的。 Laravel 是否修改了 Auth::attempt 现在的工作方式?任何帮助,将不胜感激。下面是我在 AccountController.php 中的登录功能
public function postLogin() {
$validator = Validator::make(Input::all(),
array(
'email' => 'required|email',
'password' => 'required'
)
);
if($validator->fails()) {
return Redirect::route('account-login')
->withErrors($validator)
->withInput();
}
else {
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
));
if($auth) {
Redirect::intended('/');
}
else {
return Redirect::route('account-login')
->with('global',"Email/password wrong");
}
}
return Redirect::route('account-login')
->with('global',"There was a problem signing you in.");
}
模型/User.php
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
//fillable for the database
protected $fillable = array('email','password','first-name','last-name','username','city','state','password','password_temp','code','active');
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
?>
【问题讨论】:
-
是的,我认为 Laravel 已经更改了一些安全设置,因为该 phpacademy 教程已经完成。凭记忆,只是一个简单的小东西,和 CSRF 保护什么的有关。您能否发布此文件的代码:
app/models/User.php -
@MichaelColeman 添加了它
标签: php authentication laravel laravel-4