2015-04-01 48 views
0

我在Laravel 5中創建了一個簡單的身份驗證系統。我使用Laravel 4編寫的身份驗證代碼作爲基礎。Laravel 5 - 如何在沒有電子郵件確認的情況下進行身份驗證?

我的問題是,

SQLSTATE [42S22]:列未找到:1054未知列在 'where子句'(SQL '證實':SELECT * FROM users其中email = myemail @ gmail的。 com和confirmed = 1限制1)

它看起來像Laravel正在查看我的電子郵件是否被驗證。但我不需要爲此應用程序實施註冊和驗證過程。我的問題是,如何告訴laravel 不是擔心電子郵件確認?

我的身份驗證代碼如下所示:

public function postAuthenticate() 
{ 
    // Fetch posted credentials 

    $email = \Request::input('email'); 
    $password = \Request::input('password'); 
    $remember = \Request::has('_remember'); 

    $credentials = [ 
     'email' => $email, 
     'password' => $password, 
     'confirmed' => 1 
    ]; 

    // Attempt to log in user 
    if (\Auth::attempt($credentials, $remember)) 
    { 
     return \Redirect::intended('dashboard'); 
    } 

    // If this code was reached, it means that the user failed to authenticated. 
    // In this case, redirect back to the login page with errors. 

    $messages = new Illuminate\Support\MessageBag; 
    $messages->add('Authentication Error', 'Sign in failed.'); 


    return \Redirect::to('/login') 
     ->withInput() 
     ->with('errors', $messages); 
} 

我的用戶模型的樣子:

<?php namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 

class User extends Model implements AuthenticatableContract, CanResetPasswordContract { 

    use Authenticatable, CanResetPassword; 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'users'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = ['name', 'email', 'password']; 

    /** 
    * The attributes excluded from the model's JSON form. 
    * 
    * @var array 
    */ 
    protected $hidden = ['password', 'remember_token']; 

} 

最後,我的用戶表遷移:

<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateUsersTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function(Blueprint $table) 
     { 
      $table->increments('id'); 
      $table->string('name'); 
      $table->string('email')->unique(); 
      $table->string('password', 60); 
      $table->rememberToken(); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('users'); 
    } 

} 

謝謝!

回答

0

您必須從$credentials中刪除'confirmed' => 1

例如:

$credentials = [ 
     'email' => $email, 
     'password' => $password 
]; 
+1

這樣在我的部分明顯的監督!謝謝! – clone45 2015-04-02 16:53:20

+0

最適合我!是我的第一個答案! ;) – 2015-06-11 10:02:40

相關問題