Laravel 4验证与Facebook(无密码验证) [英] Laravel 4 Auth with Facebook (no password authentication)
问题描述
我试图建立与Laravel 4的认证系统与Facebook登录。我现在用的是madewithlove / laravel-的oauth2包Laravel 4。
I'm trying to set up an authentication system with Laravel 4 with a Facebook login. I am using the madewithlove/laravel-oauth2 package for Laravel 4.
当然,没有密码对用户洛与Facebook添加到我的数据库。我,然而,试图检查,看是否有用户ID已经在数据库中,以确定是否我应该创建一个新的实体,或只要登录当前之一。我想用验证命令来做到这一点。我有一个名为粉丝表。
Of course, there is no password to add to my database upon a user loggin in with Facebook. I am, however, trying to check to see if a user id is in the database already to determine if I should create a new entity, or just log in the current one. I would like to use the Auth commands to do this. I have a table called "fans".
这是我用什么样的工作:
This is what I'm working with:
$fan = Fan::where('fbid', '=', $user['uid']);
if(is_null($fan)) {
$fan = new Fan;
$fan->fbid = $user['uid'];
$fan->email = $user['email'];
$fan->first_name = $user['first_name'];
$fan->last_name = $user['last_name'];
$fan->gender = $user['gender'];
$fan->birthday = $user['birthday'];
$fan->age = $age;
$fan->city = $city;
$fan->state = $state;
$fan->image = $user['image'];
$fan->save();
return Redirect::to('fans/home');
}
else {
Auth::login($fan);
return Redirect::to('fans/home');
}
风扇型号:
<?php
class Fan extends Eloquent {
protected $guarded = array();
public static $rules = array();
}
当我运行它,我得到的错误:
When I run this, I get the error:
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, instance of Illuminate\Database\Eloquent\Builder given
编辑:当我使用: $扇=风扇::在哪里('fbid','=',$用户['UID']) - &gt;首先();
我得到的错误:
Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Auth\UserInterface, null given, called in /Applications/MAMP/htdocs/crowdsets/laravel-master/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 368 and defined
我不知道为什么它给我这个错误。你对我怎样才能使这项工作的建议吗?谢谢你的帮助。
I do not know why it is giving me this error. Do you have suggestions on how I can make this work? Thank you for your help.
推荐答案
您必须实现的UserInterface到模型的验证才能正常工作
You have to implement UserInterface to your model for Auth to work properly
use Illuminate\Auth\UserInterface;
class Fan extends Eloquent implements UserInterface{
...
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
}
getAuthIdentifier和getAuthPassword是抽象方法,必须在你的类实现的UserInterface实施
getAuthIdentifier and getAuthPassword are abstract method and must be implemented in you class implementing UserInterface
这篇关于Laravel 4验证与Facebook(无密码验证)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!