2016-10-26 2 views
1

Laravel 5.3에서 뭔가 바뀌 었습니다.Laravel 5.3 추가 조건으로 인증

<?php 

namespace App\Http\Controllers; 

use Illuminate\Support\Facades\Auth; 

class AuthController extends Controller 
{ 
    /** 
    * Handle an authentication attempt. 
    * 
    * @return Response 
    */ 
    public function authenticate() 
    { 
     if (Auth::attempt(['email' => $email, 'password' => $password])) { 
      // Authentication passed... 
      return redirect()->intended('dashboard'); 
     } 
    } 
} 

그러나이 컨트롤러 : 문서에서이 우리가 우리의 추가 조건을 추가 할 수 있습니다 컨트롤러가

내가 그 생성해야 AuthController는 만 인 LoginController 있습니다 ..... 더 이상 존재하지 않는 AuthController 또는 무엇을?

그래서 질문은 사용자가 해당 5.3에 LoginController을 사용할 수 있습니다

'active' => 1 

답변

2

로그인하는 또 하나 개의 조건을 추가하는 방법입니다.

if (!auth()->user()->active) { 
    auth()->logout(); 
    return redirect('/'); 
} 

이것은 사용자가 자신이 활성화되지이다이고 루트에 그를 리디렉션됩니다 로그 아웃됩니다 : 당신이 원하는 것을 할 수있는 한 가지 방법은 sendLoginResponse() 방법을 무시하고 그것의 시작이 뭔가를 추가하는 것입니다. 이 작업은 active이 부울 값입니다.

+1

니스 ... 난 이런 식으로했다!을) -> user() -> active) { auth() -> logout(); return ('login') -> with ('warning', 'Sie sind noch nicht aktiviert!'); } } – lewis4u

+0

도움이 되니 기쁩니다. –

+0

질문이 하나 더 있습니다. 이제 새 사용자를 등록하면 즉시 로그인됩니다 ....이 문제를 방지하는 방법 ??? 그럼 내가 새 질문을해야 할까? – lewis4u

0

당신은 인 LoginController에서, = 1 '활성'같은 additional condition, 지정할 수 있습니다 (공공 기능 sendLoginResponse() { 경우 (인증 :

<?php 

namespace App\Http\Controllers; 

use Illuminate\Support\Facades\Auth; 

class LoginController extends Controller 
{ 
    /** 
    * Handle an authentication attempt. 
    * 
    * @return Response 
    */ 
    public function authenticate(Request $request) 
    { 
     $email = $request->input('email'); 
     $email = $request->input('email'); 
     if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) { 
      // Authentication passed... 
      return redirect()->intended('dashboard'); 
     } 
    } 
}