Laravel 5.1.11 拓展包 jenssegers/laravel-mongodb 原生auth认证

config/app.php
配置

providers =>
Jenssegers\Mongodb\MongodbServiceProvider::class,
Jenssegers\Mongodb\Auth\PasswordResetServiceProvider::class,
aliases=>'Moloquent' => 'Jenssegers\Mongodb\Model',

登录是用的auth原生app\User.php

基本没什么变化和自动生成的 就是改了下表和继承的 Model 这都是 拓展包自带的

use Jenssegers\Mongodb\Model as Eloquent;

class User extends Eloquent {
    use Authenticatable, Authorizable, CanResetPassword;

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

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

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

Bug出现的文件
vendor/laravel/framework/src/Illuminate/Auth/Guar.php

    public function attempt(array $credentials = [], $remember = false, $login = true)
    {
        $this->fireAttemptEvent($credentials, $remember, $login);

        $this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials);
        //dd($user);
        // If an implementation of UserInterface was returned, we'll ask the provider
        // to validate the user against the given credentials, and if they are in
        // fact valid we'll log the users into the application and return true.
        if ($this->hasValidCredentials($user, $credentials)) {
            if ($login) {
                $this->login($user, $remember);
            }

            return true;
        }

        return false;
    }

hasValidCredentials 提示没实例。。。

提示的内容:

ErrorException in EloquentUserProvider.php line 110:
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in /alidata/www/laravel-system/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 390 and defined
class User extends Eloquent implements AuthenticatableContract,AuthorizableContract,CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
 // codes
}
JellyBool

貌似问题已经解决了

class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
 // codes
}
AGuier
class User extends Eloquent implements AuthenticatableContract,AuthorizableContract,CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
 // codes
}
AGuier

@JellyBool 是的呀

任亮1993

@AGuier 你好,我按照你的配置配了一遍,也按照官网配置了一遍,依然是报错呢。
Failed to connect to: localhost:27017: SASL Authentication failed on database ‘admin’: Authentication failed.

我确定版本都是对的,不用框架的情况下是可以连上MongoDB的。

AGuier

你自己看咯。。。连接失败啊。 和框不框架 没关系啊。。。。@任亮1993

AGuier

@任亮1993

JellyBool

这个推送通知理论上已经发出了,只是中文的用户名没有解析成链接。。。 @AGuier

Styxhelix

@AGuier
你好,按照这个好像有点问题呢,App\User cannot use Illuminate\Foundation\Auth\User - it is not a trait,代码如下
namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent implements AuthenticatableContract,AuthorizableContract,CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;

AGuier

@Styxhelix 你没建表吗?