2017-05-24 4 views
0

電子メールとパスワードに加えてログイン中に、名前が確認された追加の列をチェックしました。私はそれはそれは今働いている以下 保護機能の資格情報(リクエスト$リクエスト)追加の列laravel auth loginを確認する

{ 
    //return $request->only($this->username(), 'password'); 
    $credentials = $request->only('email', 'password'); 
    $credentials = array_add($credentials, 'verified', '1'); 
    return $credentials; 
} 

ようAuthenticatesUser.phpに変更しました。電子メールとパスワードは一致していても検証済み= 0の場合は検証されないエラーメッセージを送信します。

答えて

0

UserController.php

public function doLogin(){ 

     // validate the info, create rules for the inputs 
     $rules = array(
      'email' => 'required|email', // make sure the email is an actual email 
      'password' => 'required|alphaNum|min:6' // password can only be alphanumeric and has to be greater than 6 characters 
      ); 

     // run the validation rules on the inputs from the form 
     $validator = Validator::make(Input::all(), $rules); 

     // if the validator fails, redirect back to the form 
     if ($validator->fails()) { 
      return Redirect::to('user/login') 
       ->withErrors($validator) // send back all errors to the login form 
       ->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form 
      } else { 
      // create our user data for the authentication 
       $userdata = array(
        'email'  => Input::get('email'), 
        'password' => Input::get('password') 
        ); 

      // attempt to do the login 
       if (Auth::attempt($userdata)) { 
       // validation successful! 
       // redirect them to the secure section or whatever 
       // check if verified 
        $user = Auth::getLastAttempted(); 
        if ($user->confirmed==1) { 
         return Redirect::to('user/dashboard'); 
        } 
        else{ 
         Auth::logout(); 
         return redirect('user/login')->with('flash_msg','Your account is not verified. Check your email for further process.')->withInput(Input::except('password')); 
        } 
       } else {   
       // validation not successful, send back to form 
        return redirect('user/login')->with('error_msg','Invalid login information, try again')->withInput(Input::except('password')); 
       } 
      } 
     } 
関連する問題