2016-05-05 5 views
0

laravelが初めてです。私はいくつかの関連記事を見たことがありますが、私は正解を見つけることができませんでした。私はphp artisan make:authを使ってauthを作った、私はディレクトリpublicPagesを持っている。 auth.loginビューを私のカスタムpublicPages.loginpublicPages.registerに変更しました。登録プロセスは正常に動作し、usersテーブルにデータを挿入します。ユーザーにはログインしません。私がloginビューとに行くとき。それはエラーを返すことも、ユーザーをログインさせることもありません。ここで登録プロセスは正常に実行されますが、ログインビューは動作していませんlaravel authentication

はルートです:

Route::auth(); 
Route::controllers([ 
    'auth' => 'Auth\AuthController', 
    'password' => 'Auth\PasswordController' 
]); 

Route::group(array('namespace' => 'UserControllers'), function() 
{ 
    Route::group(['middleware' => ['web']], function() { 
     Route::group(['middleware' => 'auth'], function() { 
     Route::get('community', '[email protected]'); 
     Route::post('communities', '[email protected]'); 
     Route::get('edit/{id}', ['as' => 'edit', 'uses' => '[email protected]']); 
     Route::get('delete/{id}', '[email protected]'); 
     Route::post('update/{id}', ['as' => 'update', 'uses' => '[email protected]']); 
     Route::get('create', '[email protected]'); 
     Route::post('idea', '[email protected]'); 
     Route::get('users', '[email protected]'); 
     Route::get('deleteUser/{id}', '[email protected]'); 
     Route::get('delete/idea/{id}', '[email protected]'); 
     Route::get('approve/{id}', '[email protected]'); 
    }); 
    }); 

コントローラー:

class UserController extends Controller { 

    //constructor 
    public function __construct() { 
     $this->middleware('auth'); 
    } 

私はそれがすべてのUserController functionのためのログインページにリダイレクトします$this->middleware('auth');使用するときに私が知っています。それはうまく動作しています。

ビュー:

<form id="login-form" class="clearfix" action="{{url('/login')}}" method="post"> 
<input type="hidden" name="_token" value="{{ csrf_token() }}"> 
<p class="rs pb30">Please Provide your Credentials to Verify Your Identity</p> 
<div class="form form-post-comment"> 
<div class="fa-align-center"> 
<label for="login_email"> 
<input id="login_email" type="email" name="email" class="txt fill-width txt-name{{ $errors->has('email') ? ' has-error' : '' }}" placeholder="Enter Your Email" required="required"/> 
</label> 
@if ($errors->has('email')) 
    <span class="help-block"> 
    <strong>{{ $errors->first('email') }}</strong> 
    </span> 
@endif 
<br><br> 
<label for="password"> 
<input id="password" type="password" name="login_password" class="txt fill-width txt-email" placeholder="Enter Your Password" required="required"/> 
</label> <br><br> 
<label for="links"> 
<a href="/changepassword" class="txt-emphasis">Forgotten Password?</a> 
<p>Don't have an account? <a href="/register" class="txt-emphasis">Register Here</a> </p> 
</label> 
</div> 

<div class="clear"></div> 
<p > 
<span id="response"></span> 
{{--<input type="submit" class="btn btn-submit-comment" value="Login">--}} 
<button class="btn btn-submit-comment" form="login-form">Login</button> 
</p> 
</div> 

ここではAuthenticatesUsersファイルです:

<?php 

namespace Illuminate\Foundation\Auth; 

use Illuminate\Http\Request; 
use Illuminate\Support\Facades\Auth; 
use Illuminate\Support\Facades\Lang; 
//use App\Http\Requests\UserRequest; 

trait AuthenticatesUsers 
{ 
    use RedirectsUsers; 

    /** 
    * Show the application login form. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function getLogin() 
    { 
     return $this->showLoginForm(); 
    } 

    /** 
    * Show the application login form. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function showLoginForm() 
    { 
     $view = property_exists($this, 'loginView') 
        ? $this->loginView : 'auth.authenticate'; 

     if (view()->exists($view)) { 
      return view($view); 
     } 

     return view('publicPages.login'); 
    } 

    /** 
    * Handle a login request to the application. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function postLogin(Request $request) 
    { 
     return $this->login($request); 
    } 

    /** 
    * Handle a login request to the application. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function login(Request $request) 
    { 
     $this->validateLogin($request); 

     // If the class is using the ThrottlesLogins trait, we can automatically throttle 
     // the login attempts for this application. We'll key this by the username and 
     // the IP address of the client making these requests into this application. 
     $throttles = $this->isUsingThrottlesLoginsTrait(); 

     if ($throttles && $lockedOut = $this->hasTooManyLoginAttempts($request)) { 
      $this->fireLockoutEvent($request); 

      return $this->sendLockoutResponse($request); 
     } 

     $credentials = $this->getCredentials($request); 

     if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) { 
      return $this->handleUserWasAuthenticated($request, $throttles); 
     } 

     // If the login attempt was unsuccessful we will increment the number of attempts 
     // to login and redirect the user back to the login form. Of course, when this 
     // user surpasses their maximum number of attempts they will get locked out. 
     if ($throttles && ! $lockedOut) { 
      $this->incrementLoginAttempts($request); 
     } 

     return $this->sendFailedLoginResponse($request); 
    } 

    /** 
    * Validate the user login request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return void 
    */ 
    protected function validateLogin(Request $request) 
    { 
     $this->validate($request, [ 
      $this->loginUsername() => 'required', 'password' => 'required', 
     ]); 
    } 

    /** 
    * Send the response after the user was authenticated. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param bool $throttles 
    * @return \Illuminate\Http\Response 
    */ 
    protected function handleUserWasAuthenticated(Request $request, $throttles) 
    { 
     if ($throttles) { 
      $this->clearLoginAttempts($request); 
     } 

     if (method_exists($this, 'authenticated')) { 
      return $this->authenticated($request, Auth::guard($this->getGuard())->user()); 
     } 

     return redirect()->intended($this->redirectPath()); 
    } 

    /** 
    * Get the failed login response instance. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    protected function sendFailedLoginResponse(Request $request) 
    { 
     return redirect()->back() 
      ->withInput($request->only($this->loginUsername(), 'remember')) 
      ->withErrors([ 
       $this->loginUsername() => $this->getFailedLoginMessage(), 
      ]); 
    } 

    /** 
    * Get the failed login message. 
    * 
    * @return string 
    */ 
    protected function getFailedLoginMessage() 
    { 
     return Lang::has('auth.failed') 
       ? Lang::get('auth.failed') 
       : 'These credentials do not match our records.'; 
    } 

    /** 
    * Get the needed authorization credentials from the request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return array 
    */ 
    protected function getCredentials(Request $request) 
    { 
     return $request->only($this->loginUsername(), 'password'); 
    } 

    /** 
    * Log the user out of the application. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function getLogout() 
    { 
     return $this->logout(); 
    } 

    /** 
    * Log the user out of the application. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function logout() 
    { 
     Auth::guard($this->getGuard())->logout(); 

     return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/'); 
    } 

    /** 
    * Get the guest middleware for the application. 
    */ 
    public function guestMiddleware() 
    { 
     $guard = $this->getGuard(); 

     return $guard ? 'guest:'.$guard : 'guest'; 
    } 

    /** 
    * Get the login username to be used by the controller. 
    * 
    * @return string 
    */ 
    public function loginUsername() 
    { 
     return property_exists($this, 'username') ? $this->username : 'email'; 
    } 

    /** 
    * Determine if the class is using the ThrottlesLogins trait. 
    * 
    * @return bool 
    */ 
    protected function isUsingThrottlesLoginsTrait() 
    { 
     return in_array(
      ThrottlesLogins::class, class_uses_recursive(static::class) 
     ); 
    } 

    /** 
    * Get the guard to be used during authentication. 
    * 
    * @return string|null 
    */ 
    protected function getGuard() 
    { 
     return property_exists($this, 'guard') ? $this->guard : null; 
    } 
} 

私はpostLoginForm()に変更する必要はありますか?おかげ

はアップデート2: 私は

if (Auth::attempt(['email' => $email, 'password' => $password])) { 
      // Authentication passed... 
      return redirect()->intended('dashboard'); 
     } else { 
echo 'not logged in'; 
} 

postLoginForm()関数のコードを変更した今、ようやくそれがnot logged inを出力しますが、それは自動的に適用されるためにも、私は、それがnot logged in言うtrue資格情報、

答えて

0

Try to remove web middleware from routes.phpを使用します5.2.27以降、手動で適用すると、あなたのようなエラーが発生する可能性があります。

+0

あなたの返信ありがとう、私もそれを試みました。最初は 'routes.php'にはありませんでした。 @Alexey Mezenin –

+0

'showLoginForm'関数のビューパスを更新しましたか? – Vikas

+0

これはshowLoginFormです。public function showLoginForm() { $ view = property_exists($ this、 'loginView') ?$ this-> loginView: 'auth.authenticate'; if(view() - > exists($ view)){ return view($ view); } 戻るビュー( 'auth.login'); } 'ビューを戻す( 'auth.login')'をビュー( 'publicPages.login)'に戻す必要がありますか? –

0

あなたのルートファイルによれば、ログインルートは/auth/loginではなく、/loginです。だから私はあなたのようにあなたのビューファイル内のアクションを変更することをお勧め:Route::auth();ので

action="{{url('/auth/login')}}" 

EDIT

はすでに、あなたのルートには、次の必要はありません 、あなたのルートファイルの先頭に追加されますファイル:

Route::controllers([ 
    'auth' => 'Auth\AuthController', 
    'password' => 'Auth\PasswordController' 
]); 

これを削除して、ログインフォームに戻してください。

+0

私もそれを変更しました。しかし何も働かなかった。 'login'ビューは、間違った入力に対して何の認証エラーも与えず、ユーザにログインしません。 –

+0

@QasimAli - コードの一部を削除したときに私の回答 – Vikas

+0

を更新しました。それは 'NotFoundHttpException'を投げています@Vikas –

関連する問題