2017-08-03 14 views
1

私はlaravelを初めて使うので少し混乱します。正しい認証でapplicant/homeにリダイレクトされるべきフォームの動作のURLから常にapplicant/loginに私をリダイレクトします。Laravelは間違ったパスワードでも認証にログインします

public function authenticate(Request $request) 
{ 
    $credentials = $request->only('email', 'password'); 

    if ($this->guard()->attempt($credentials)) { 
     /* 
     $user = Admin::where('email', $credentials['email'])->first(); 
     // Authentication passed... 
     $this->guard()->loginUsingId($user->id); 
     */ 
     return redirect()->intended('applicant/home'); 
    } 

    return view('applicants.home'); 
} 

はここに私のフォームのコードです:

<form method="post" action="{{ url('/applicants/login') }}"> 
    {!! csrf_field() !!} 

    <div class="form-group has-feedback {{ $errors->has('email') ? ' has-error' : '' }}"> 
     <input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email"> 
     <span class="glyphicon glyphicon-envelope form-control-feedback"></span> 
     @if ($errors->has('email')) 
      <span class="help-block"> 
      <strong>{{ $errors->first('email') }}</strong> 
     </span> 
     @endif 
    </div> 

    <div class="form-group has-feedback{{ $errors->has('password') ? ' has-error' : '' }}"> 
     <input type="password" class="form-control" placeholder="Password" name="password"> 
     <span class="glyphicon glyphicon-lock form-control-feedback"></span> 
     @if ($errors->has('password')) 
      <span class="help-block"> 
      <strong>{{ $errors->first('password') }}</strong> 
     </span> 
     @endif 

    </div> 
    <div class="row"> 
     <div class="col-xs-8"> 
      <div class="checkbox icheck"> 
       <label> 
        <!--<input type="checkbox" name="remember"> Remember Me --> 
       </label> 
      </div> 
     </div> 
     <!-- /.col --> 
     <div class="col-xs-4"> 
      <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button> 
     </div> 
     <!-- /.col --> 
    </div> 
</form> 
+0

にログインした場合、彼らはログインするように要求またはアクセス権が付与されますのいずれか、あなたはlaravelのデフォルトの認証を使用することがありますか? – Gunaseelan

+0

ログインが必要なページで認証されたルータミドルウェアがありますか? – Jorn

答えて

1

Laravelはデフォルトで認証方法を持っている

は、ここに私のコントローラで私のコードです。

メイク:ファイルとphp artisan make:auth

フォルダが作成されます。

あなたはログインフォームを持っている

/resources/views/auth/login.blade.php

今すぐあなたのフォームの必須はここに次のようになります。

<form method="post" action="{{ url('/login') }}"> 
      {!! csrf_field() !!} 

      <div class="form-group has-feedback {{ $errors->has('email') ? ' has-error' : '' }}"> 
       <input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email"> 
       <span class="glyphicon glyphicon-envelope form-control-feedback"></span> 
       @if ($errors->has('email')) 
        <span class="help-block"> 
        <strong>{{ $errors->first('email') }}</strong> 
       </span> 
       @endif 
      </div> 

      <div class="form-group has-feedback{{ $errors->has('password') ? ' has-error' : '' }}"> 
       <input type="password" class="form-control" placeholder="Password" name="password"> 
       <span class="glyphicon glyphicon-lock form-control-feedback"></span> 
       @if ($errors->has('password')) 
        <span class="help-block"> 
        <strong>{{ $errors->first('password') }}</strong> 
       </span> 
       @endif 

      </div> 
      <div class="row"> 
       <div class="col-xs-8"> 
        <div class="checkbox icheck"> 
         <label> 
          <!--<input type="checkbox" name="remember"> Remember Me --> 
         </label> 
        </div> 
       </div> 
       <!-- /.col --> 
       <div class="col-xs-4"> 
        <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button> 
       </div> 
       <!-- /.col --> 
      </div> 
     </form> 

そして

アプリ/ HTTP /コントローラ/認証

にあなたは

LoginControllerを持っています.php

、内側:

class LoginController extends Controller 
{ 
you must have this: 

protected $redirectTo = '/home'; home, or what you want;) 
} 

また、あなたが持っている(ルートファイル)web.phpにチェック:

Auth::routes(); 
+0

助けてくれてありがとう私はすでにそれをどのように把握!どうもありがとうございます! :) –

+0

@JayzdeVeraあなたは大歓迎です。私の答えがあなたに役立つなら、それを正しいものとしてください;)Laravelの質問があれば、あなたはこの答えのコメントにURLをつけることができます。私はあなたを助けようとします。ハッピーコード! –

1

私はあなたがこれはあなたのために役立つかもしれ試すことができると思います。

laravelのデフォルト認証をログインに使用して、ユーザーを登録してください:

php artisan make:auth 

このヘルプをお待ちしています。

+0

助けてくれてありがとう!私はすでにそれを理解する! –

+0

@JayzdeVera:喜んで私の答えがあなたの解決策なら、私の答えを受け入れてください。 –

1

@LluísPuig Ferrerが示唆したように、LaravelのビルドをAuthで使用します。オンライン上には多くのドキュメントがあります。

web.php内に経路を定義してauth middlewareを使用するようにしてください。ユーザーがauth middlewareを使用するページにアクセスしようとする場合、既に

Route::group(['middleware' => 'auth'], function() { 
    // All the routes that require login authentication 
}; 
+0

私はそれを理解します! :)ありがとうbtw :) –

関連する問題