2013-09-26 12 views
8

Mam login na Facebooku, który wykonuję z OAuth2, a następnie używam Laravel 4 z wbudowanym System uwierzytelniania, który umożliwia ponowne zalogowanie użytkownika podczas ponownej wizyty. Dla większości użytkowników, nie widzę żadnych problemów z tym, co mam, ale dla jednego użytkownika, on widzi następujący błąd pojawia się przy logowaniu:Argument 1 przekazany do Illuminate Auth Guard :: login() musi zaimplementować interfejs Illuminate Auth UserInterface, null podany jako otwarty:

ErrorException 
Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Auth\UserInterface, null given 
open: */nfs/c09/h04/mnt/139243/domains/crowdsets.com/vendor/laravel/framework/src/Illuminate/Auth/Guard.php 
*  /** 
     * Log a user into the application. 
     * 
     * @param \Illuminate\Auth\UserInterface $user 
     * @param bool $remember 
     * @return void 
     */ 
     public function login(UserInterface $user, $remember = false) 
     { 
       $id = $user->getAuthIdentifier(); 

Oto odpowiedni kod logowanie/uwierzytelniania w kontrolerze:

$check = Fan::where('fbid', '=', $user['uid'])->first(); 

       if(is_null($check)) { 

        $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_abbrev; 
        $fan->image = $user['image']; 
        $fan->friend_ids_url = $user['friends']; 
        $fan->friend_ids_unpacked = $friend_ids; 

        $fan->save(); 

        $new = Fan::where('fbid', '=', $user['uid'])->first(); 

        Auth::login($new); 
        return Redirect::to('fans/home'); 

       } 

       else { 

        Auth::login($check); 

        $fan = Fan::find(Auth::user()->id); 
        $fan->image = $user['image']; 
        $fan->save(); 

        return Redirect::to('fans/home'); 
        var_dump($user); 

       } 

to jest mój kod w modelu dla tabeli używam zachować dane użytkownika, zwany „Fani”:

<?php 

use Illuminate\Auth\UserInterface; 

class Fan extends Eloquent implements UserInterface { 
    protected $guarded = array(); 

    public static $rules = array(); 

    public function getAuthIdentifier() 
{ 
return $this->getKey(); 
} 


public function getAuthPassword() 
{ 
return $this->password; 
} 

to jest bardzo kłopotliwy, bo to logowanie działa dla wszystkich z inne profile, które próbowałem. Tylko z profilem tego przyjaciela rzuca ten błąd. Dodam również, że przy logowaniu (lub ponownych próbach) utworzy wiele wpisów dla tego użytkownika w bazie danych/tabeli. Ten system uwierzytelniania powinien zostać skonfigurowany, aby temu zapobiec. Czy jest coś, czego mi brakuje?

+0

to masz rozwiązany? jeśli tak, czy podzielisz się swoimi przemyśleniami? –

Odpowiedz

0

Zamiast Auth::login($check); lub Auth::login($new); należy przekazać,

Auth::login(Auth::user()); 

funkcja auth :: login() przyjmuje jako pierwszy parametr userinterface Object jak public function login(UserInterface $user, $remember = false) i funkcji w organizmie, to zajmie userid tak $id = $user->getAuthIdentifier();

Przeczytaj dokumentację API Doc here.

+0

Kiedy próbuję tego, pojawia się następujący błąd logowania: Argument 1 przekazany do Illuminate \ Auth \ Guard :: login() musi zaimplementować interfejs Illuminate \ Auth \ UserInterface, null given – user1072337

+0

Jak już wcześniej wspomniałem, używając $ czek i $ nowe wartości działa dla większości użytkowników. Niedawno widziałem ten błąd u 1 użytkownika. – user1072337

2

Proste pytanie i odpowiedź:
Czy Twoja klasa Fan przedłużyć User klasę (lub realizuje UserInterface)?
Jeśli nie, to najprostszy sposób, aby naprawić to

class Fan extends User{ 
    .... 
} 
+0

Jak widać powyżej, mam zaimplementować interfejs UserInterface w tym wierszu: użyj Illuminate \ Auth \ UserInterface; Wentylator klasy rozszerza Eloquent implementuje UserInterface { – user1072337

+0

Mam też już klasę fanów rozszerzającą Eloquent ... o inne pomysły? – user1072337

4

Spróbuj byłaby kodu do tego:

$fan = Fan::where('fbid', '=', $user['uid'])->first(); 

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_abbrev; 
    $fan->image = $user['image']; 
    $fan->friend_ids_url = $user['friends']; 
    $fan->friend_ids_unpacked = $friend_ids; 

    $fan->save(); 
} else { 
    $fan->image = $user['image']; 
    $fan->save(); 
} 

Auth::loginUsingId($fan->getAuthIdentifier()); 
return Redirect::to('fans/home'); 
0

spróbować. Rozwiązałem własne.

$fan = User:where('id',$socialUser->getId())->first(); 
if(!$fan){ 
    **$fan** = User:create([ 
     'facebook_id' => $socialUser->getId(), 
     'email' => $socialUser->getEmail() 
    ]); 
auth()->login($fan); 
return return->to('whereYouLike'); 
} 
0

miałem ten sam problem i udało mi się go rozwiązać, sprawdzając kilka rzeczy:

Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Auth\UserInterface, null given open:

  • Jak widać, null given oznacza, że ​​$user chcesz Auth::login($user) jest null . Sprawdź, czy ustawiona jest zmienna.
  • Nie wstawiaj żadnego var_dump() między Auth :: login a ostatecznym przekierowaniem(). Może zatrzymać Authentification.

Nadzieja pomaga

3

w metodzie Create() w LoginController należy zwrócić $ user że pracował dla mnie

protected function create(array $data) 
    { 
     $user = User::create([ 
      'username' => $data['username'], 
      'email' => $data['email'], 
      'password' => bcrypt($data['password']), 
     ]); 

     return $user; 
    } 
Powiązane problemy