2016-08-23 20 views
2

私はLaravel 5.0を使用しています。シングルサインオンを使用してLaravelプロジェクトにアクセスしているため、ユーザー名(パスワードなし)のみでログインしたいので、シングルサインオンで成功した場合、ログインしたユーザーのユーザー名登録されているかどうか。
私は一日中これを探していますが、私はまだ手がかりを見つけました。

は私がエラーを持っている:Laravel 5.0でAuth :: attemptを使用してパスワードなしでログインする方法は?

私は私のLoginControllerに以下のコードを使用していた場合

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

:私は私のLoginControllerに以下のコードを使用していた場合

$user = User::where('USER_NAME', '=', $_GET['UserName'])->first(); 
if(Auth::login($user)->USER_ID == $_GET['UserName']){ 
    return redirect('Home'); 
} 

をそして:

if(Auth::attempt(['USER_ID' => $_GET['UserName']])){ 
    return redirect('Home'); 
} 

エラーが発生しました:

Undefined index: password

答えて

0

ドキュメントによると:だから

the user will be retrieved by the value of the email column. If the user is found, the hashed password stored in the database will be compared with the hashed password value passed to the method via the array.

、パスワードは、この方法でチェックする必要がありますので、それは必須のパラメータです。

次のようにログインすることができます。

$user = User::where('USER_NAME', '=', $_GET['UserName'])->first(); 

if (empty($user)) { 
    abort(404); 
} 

if(Auth::loginUsingId($user->id)){ 
    return redirect('Home'); 
} 
+0

私はそれを試してみました、私はApplication.phpライン901にエラー 'NotFoundHttpException持っている:' – hendraspt

+0

わからないが。私は自分のコードで試したが、うまくいきました。 – Sovon

0

あなたはメールでのみ手動authencateユーザーをすることができます。このように:

public function authenticate(Request $request) 
    { 
       $email=$request->get('email'); 
       if (Auth::attempt(['email' => $email)) 
       {  
        return redirect()->intended('/'); 
       } 
       else 
       { 
        return redirect('/login'); 
       } 

    } 
+0

私はこのコードを追加する必要がありました – vinox

関連する問題