基本上,我希望允许用户使用他们的电子邮件地址和密码登录,但是使用一个自动递增ID作为用户表的主键。
一些教程似乎表明这是非常直接的。但这似乎不适合我。首先,我不得不修改用户模型以使用"email“作为身份验证标识符。这是可行的,但会话不保存(见下文)。
用户表迁移文件;
Schema::create("users", function ($table) {
$table->increments("id");
$table->string("email", 255)->unique();
$table->string("password", 60);
$table->timestamps();
});用户模型文件;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'users';
protected $hidden = array('password');
public function getAuthIdentifier() {
return $this->email;
}
public function getAuthPassword() {
return $this->password;
}
public function getReminderEmail() {
return $this->email;
}
}登录;
Auth::attempt(array("email" => Input::get("email"), "password" => Input::get("password")), true);...works (如返回true)。但是,会话没有正确保存。随后的任何请求都没有经过身份验证。我尝试过不同的会话驱动程序,但没有成功。
如果我加上;
protected $primaryKey = "email";对于用户模型,会话可以工作。但是不能正确,因为"email“不是该表的主键,"id”是(我想把"id“保留为主键)。
还: 正式文件似乎表明您不必做任何特殊的事情来使用"email“作为标识列,因为"email”是使用这里的,但是数字ID则使用这里。我是不是漏掉了什么明显的东西?
发布于 2013-07-16 10:15:53
我昨天花了所有的时间来解决这个问题,今天我基本上把用户模型恢复到了最初的样子;
public function getAuthIdentifier() {
return $this->getKey();
}...and它正在工作(我可以用电子邮件/密码登录,我的会话会让我登录)。
我不知道为什么昨天这不管用。与创建会话哈希的方式有关吗?我没有头绪。
https://stackoverflow.com/questions/17672821
复制相似问题