2016-03-27 10 views
1

を使用してログイン私は 幼虫5 |複数の識別子

  • または電話番号(利用可能ないくつかの)彼/彼女の

    • ユーザ名
    • または電子メールIDを提供することで、ユーザのログインを聞かせしたい

    FacebookやLinkedInでの動作と似ています。

    Laravel 5.2のデフォルト認証を使用してこれを達成するには、どのような方法が最適ですか?

  • +0

    あなたは、デフォルトの認証 –

    +0

    をさらに開発(拡張)することができます。ちょうどそこに拡張/より良い方法があるのだろうかと思っていました。 –

    +0

    私は知っている限り私が知っている限り、そして最善の方法は、自分自身を行うことです、そうでなければサードパーティの認証を使用する必要があります –

    答えて

    1

    私の知る限り、第三者の解決策はありません。 ここに私がどのようにしているかという私の実例があります... postLoginいくつかのサンプルコードです。

    $credentials = $this->getCredentials($request); 
    
    $credentials_username = ['username'=>$credentials['username'], 'password'=>$credentials['password']]; 
    $credentials_email  = ['email'=>$credentials['username'], 'password'=>$credentials['password']]; 
    $credentials_phone  = ['phone'=>$credentials['username'], 'password'=>$credentials['password']]; 
    
    //adedd custom, we also want to check by username too 
    if (Auth::attempt($credentials_email, $request->has('remember'))) { 
        return $this->handleUserWasAuthenticated($request, $throttles); 
    
    //also check for the username if exists then login to the system  
    }elseif (Auth::attempt($credentials_username, $request->has('remember'))) { 
        return $this->handleUserWasAuthenticated($request, $throttles); 
    
    //also check for phone no  
    }elseif (Auth::attempt($credentials_phone, $request->has('remember'))) { 
        return $this->handleUserWasAuthenticated($request, $throttles); 
    } 
    
    関連する問題