2017-02-21 65 views
-1

我是Laravel的新手,我已經爲用戶完成了一個系統。驗證用戶是通過「php artisan make:auth」完成的,我在users表中有一列名爲activated;當activated = 0,我不希望用戶登錄。請給我一點幫助?對不起,如果這個線索很無聊。不允許不活躍的用戶在Laravel登錄

回答

-1

我發現我自己,我只需添加這myLoginController.php

protected function credentials(Request $request) 
{ 
    $credentials = $request->only($this->username(), 'password'); 
    $credentials['activated'] = 1; 

    return $credentials; 
} 
0

你將要處理這既爲使用AuthenticatesUsers性狀或您AuthController手動一部分通過檢查你的登錄表單響應並返回適當的迴應:

<?php 

namespace App\Http\Controllers; 

use App; 

use Illuminate\Auth\AuthManager; 
use Illuminate\Foundation\Auth\AuthenticatesUsers; 

/** 
* Class AuthController 
* @package Speechlink\Http\Controllers\Auth 
*/ 
class AuthController extends Controller 
{ 
    use AuthenticatesUsers; 

    /** 
    * Create a new authentication controller instance. 
    * @param AuthManager  $auth 
    */ 
    public function __construct(AuthManager $auth) 
    { 
     $this->auth = $auth; 
    } 

    /** 
    * Deal with the login attempt (overrides the trait's postLogin method) 
    * 
    * @param Request $request 
    * @return $this|\Illuminate\Http\RedirectResponse 
    */ 
    public function postLogin(Request $request) 
    { 
     $this->validate($request, [ 
      'username' => 'required', 
      'password' => 'required', 
     ]); 

     $credentials = $request->only('username', 'password'); 

     if ($this->auth->attempt($credentials)) { 
      // We authenticated so continue 
      return redirect('path/to/logged_in'); 
     } else { 
      // We failed authentication so redirect somewhere else 
      return redirect('path/to/disabled_user'); 
     } 

    } 
}