laravel4中的身份验证错误

时间:2014-07-09 10:11:03

标签: class authentication laravel-4

早上好伙伴们,请我在我的应用程序上进行登录验证 但我想对登录凭据进行验证。所以这就是我做的,这是我的错误。 在我的模型/目录中

class Login Extends Eloquent
{
    protected $table = 'pb_user';
}

然后在我的 auth.php

    <?php

return array(

    /*
    |--------------------------------------------------------------------------
    | Default Authentication Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the authentication driver that will be utilized.
    | This driver manages the retrieval and authentication of the users
    | attempting to get access to protected areas of your application.
    |
    | Supported: "database", "eloquent"
    |
    */

    'driver' => 'eloquent',

    /*
    |--------------------------------------------------------------------------
    | Authentication Model
    |--------------------------------------------------------------------------
    |
    | When using the "Eloquent" authentication driver, we need to know which
    | Eloquent model should be used to retrieve your users. Of course, it
    | is often just the "User" model but you may use whatever you like.
    |
    */

    'model' => 'Login',

    /*
    |--------------------------------------------------------------------------
    | Authentication Table
    |--------------------------------------------------------------------------
    |
    | When using the "Database" authentication driver, we need to know which
    | table should be used to retrieve your users. We have chosen a basic
    | default value but you may easily change it to any table you like.
    |
    */

    'table' => 'pb_user',

    /*
    |--------------------------------------------------------------------------
    | Password Reminder Settings
    |--------------------------------------------------------------------------
    |
    | Here you may set the settings for password reminders, including a view
    | that should be used as your password reminder e-mail. You will also
    | be able to set the name of the table that holds the reset tokens.
    |
    | The "expire" time is the number of minutes that the reminder should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'reminder' => array(

        'email' => 'emails.auth.reminder',

        'table' => 'password_reminders',

        'expire' => 60,

    ),

);

然后我的 LoginController.php 用于登录

class LoginController extends BaseController {

/*
|--------------------------------------------------------------------------
| Default Home Controller
|--------------------------------------------------------------------------
|
| You may wish to use controllers instead of, or in addition to, Closure
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
|   Route::get('/', 'HomeController@showWelcome');
|
*/

public function get_login_data()
{

     $pb_login_email=Input::get('pb-login-email');
     $pb_login_password=Input::get('pb-login-pass');

     $date_reg=date('Y-m-d');
     $time_reg=date('r');

    /* hashed the password */

     $pb_login_password_hashed = Hash::make($pb_login_password);

     /* encrypt the email and password */

     $pb_login_email_crypted = Crypt::encrypt($pb_login_email);

    /* validate if the user has has an account */

    // goto the database first and get the data before authenticating 
    // because of the diffrent type of hash....

    /*$pb_login_email=DB::table('pb_user')->where('email', 'udemesamuel256@gmail.com')->first();
    $users = DB::table('pb_user')
                ->where('email', '=', $pb_login_email_crypted)
                ->get();

    var_dump($users->email);*/

    if (Auth::attempt(array('email' => $pb_login_email, 'password' => $pb_login_password)))
    {
        return Redirect::to('http://facebook.com');
    }

    else
    {
        return Login::all();
    }



}

}

这是错误。

    ErrorException
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Auth\UserInterface, instance of Login given, called in /var/www/laravel4/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 370 and defined

然后,当我尝试从登录类中删除表属性时:

class Login Extends Eloquent
{
    //protected $table = 'pb_user';
}

错误是:

    Illuminate \ Database \ QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'popibay.logins' doesn't exist (SQL: select * from `logins` where `email` = theresasamuel@gmail.com limit 1)

注意:请通过示例和链接支持您的答案,以便快速了解。

1 个答案:

答案 0 :(得分:0)

这是因为Laravel期望您用于Auth的模型实现UserInterface。这就像class Login extends Eloquent implements UserInterface {

一样简单

但是,您现在必须在UserInterface中实现这些方法。如果您查看Illuminate\Auth\UserInterface,您会看到以下内容:

/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier();

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword();

/**
 * Get the token value for the "remember me" session.
 *
 * @return string
 */
public function getRememberToken();

/**
 * Set the token value for the "remember me" session.
 *
 * @param  string  $value
 * @return void
 */
public function setRememberToken($value);

/**
 * Get the column name for the "remember me" token.
 *
 * @return string
 */
public function getRememberTokenName();

您可以在Laravel提供的用户模型中看到这些是如何实现的。

相关问题