Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 199 forks source link

Undefined property error in authentication #188

Closed abhivachan closed 7 years ago

abhivachan commented 7 years ago

I am using laravel 5.3 and installed in Homestead. I have followed the below steps

  1. Installed neo4j
  2. Followed the steps Vinelab/NeoEloquent related configurations.
  3. From laravel 5.3, I am able to connect to neo4j without any issues. I am able to create the user label with properties like (firstname, lastname, email, password etc.). Password is encrypted using bcrypt
  4. No modification in Auth.php file.
  5. Updated the method register in AppServiceProvider with the below line $this->app->bind(\Illuminate\Database\Eloquent\Model::class, \Vinelab\NeoEloquent\Eloquent\Model::class);
  6. My Label details are below Label Name: User Data: { "firstname": "suresh", "isactive": "yes", "created_at": "2016-10-09 12:27:23", "middlename": "", "title": "suresh subramanian", "created_by": "ssuresh", "lastname": "subramanian", "password": "$2y$10$Ddr/y8LmVD6lvStB0dcj4OPlC.UjqC2CMjzozOkJ4kvXTNe1/isUi", "updated_at": "2016-10-09 12:27:23", "isadmin": "yes", "updated_by": "ssuresh", "name": "ssuresh", "email": "ssuresh@example.com" } ], "meta": [ { "id": 182, "type": "node", "deleted": false } ], "graph": { "nodes": [ { "id": "182", "labels": [ "User" ], "properties": { "firstname": "suresh", "isactive": "yes", "created_at": "2016-10-09 12:27:23", "middlename": "", "title": "suresh subramanian", "created_by": "ssuresh", "lastname": "subramanian", "password": "$2y$10$Ddr/y8LmVD6lvStB0dcj4OPlC.UjqC2CMjzozOkJ4kvXTNe1/isUi", "updated_at": "2016-10-09 12:27:23", "isadmin": "yes", "updated_by": "ssuresh", "name": "ssuresh", "email": "ssuresh@example.com" } } ], "relationships": [] } } ], "stats": { "contains_updates": false, "nodes_created": 0, "nodes_deleted": 0, "properties_set": 0, "relationships_created": 0, "relationship_deleted": 0, "labels_added": 0, "labels_removed": 0, "indexes_added": 0, "indexes_removed": 0, "constraints_added": 0, "constraints_removed": 0 } } ], "errors": [], "responseTime": 21 }

When I try to login with user id and password, the error is below

ErrorException in CypherGrammar.php line 99: Undefined property: Illuminate\Database\Query\Builder::$matches

in CypherGrammar.php line 99 at HandleExceptions->handleError('8', 'Undefined property: Illuminate\Database\Query\Builder::$matches', '/home/vagrant/workbasket/php/projects/sample.dev/vendor/vinelab/neoeloquent/src/Vinelab/NeoEloquent/Query/Grammars/CypherGrammar.php', '99', array('query' => object(Builder), 'components' => array('matches', 'from', 'with', 'wheres', 'unions', 'columns', 'orders', 'offset', 'limit'), 'component' => 'matches', 'cypher' => '')) in CypherGrammar.php line 99 at CypherGrammar->compileComponent(object(Builder), array('matches', 'from', 'with', 'wheres', 'unions', 'columns', 'orders', 'offset', 'limit'), 'matches') in CypherGrammar.php line 72 at CypherGrammar->compileComponents(object(Builder)) in CypherGrammar.php line 29 at CypherGrammar->compileSelect(object(Builder)) in Builder.php line 1581 at Builder->toSql() in Builder.php line 1648 at Builder->runSelect() in Builder.php line 1634 at Builder->get(array('')) in Builder.php line 613 at Builder->getModels(array('')) in Builder.php line 318 at Builder->get(array('*')) in Builder.php line 288 at Builder->first() in EloquentUserProvider.php line 104

abhivachan commented 7 years ago

I have further debugged the PHP code and getting error in

Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Sample\NeoUser given, called in /home/vagrant/workbasket/php/projects/sample.dev/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 387

heydavid713 commented 7 years ago

Can you post your User Model?

abhivachan commented 7 years ago
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Vinelab\NeoEloquent\Eloquent;
use Vinelab\NeoEloquent\Facade\Neo4jSchema;

class NeoUser extends NeoEloquent
{
    protected $table = 'User';
    protected $connection = 'neo4j';
    protected $fillable = ['name','title','firstname','middlename','lastname','email','password','isadmin','isactive','created_by', 'updated_by'];
    public function createUser()
    {
        $user = NeoUser::create(
            [
                'name'  => 'ssuresh',
                'title' => 'suresh subramanian',
                'firstname' =>'suresh',
                'middlename'=>'',
                'lastname' => 'subramanian',
                'email'=>'ssuresh@example.com',
                'password' => bcrypt('password'),
                'isadmin' => 'yes',
                'isactive' => 'yes',
                'created_by' => 'ssuresh',
                'updated_by' => 'ssuresh'
            ]);
        $user->save();
    }
}
abhivachan commented 7 years ago
composer.json
 "vinelab/neoeloquent": "1.4.*",

config\database.php
'neo4j' => [
            'driver' => 'neo4j',
            'host'   => 'localhost',
            'port'   => '7474',
            'username' => 'neo4j',
            'password' => 'neo4j_password'
        ],
Auth.php
'providers' => [
      'users' => [
            'driver' => 'eloquent',
            'model' => Sample\NeoUser::class,
        ]
    ],

App.php
'Vinelab\NeoEloquent\NeoEloquentServiceProvider',

AppServiceProvider.php > register()
$this->app->bind(\Illuminate\Database\Eloquent\Model::class, \Vinelab\NeoEloquent\Eloquent\Model::class);
abhivachan commented 7 years ago

Any help will be really appreciated. :-)

heydavid713 commented 7 years ago

Well the User is missing theimplements \Illuminate\Contracts\Auth\Authenticatable, \Illuminate\Contracts\Auth\CanResetPassword interfaces from the original Laravel User, they also work in NeoEloquent. Those are the ones that make Auth possible in Eloquent in general.

abhivachan commented 7 years ago

Thanks for your help . :-). I tried and getting another property error. array_filter() expects parameter 1 to be array, null given in Grammar.php line 812.

Is there example implementation will be really helpful?. I am not sure what I am really missing it.

My revised model is below.

class NeoUser extends NeoEloquent implements Authenticatable, CanResetPassword
{
    protected $table = 'User';
    protected $connection = 'neo4j';
    protected $fillable = ['name','title','firstname','middlename','lastname','email','password','isadmin','isactive','created_by', 'updated_by'];
    public function createUser()
    {
        $user = NeoUser::create(
            [
                'name'  => 'ssuresh',
                'title' => 'suresh subramanian',
                'firstname' =>'suresh',
                'middlename'=>'',
                'lastname' => 'subramanian',
                'email'=>'ssuresh@example.com',
                'password' => bcrypt('password'),
                'isadmin' => 'yes',
                'isactive' => 'yes',
                'created_by' => 'ssuresh',
                'updated_by' => 'ssuresh'
            ]);
        $user->save();
    }

    /**
     * Get the e-mail address where password reset links are sent.
     *
     * @return string
     */
    public function getEmailForPasswordReset()
    {
        // TODO: Implement getEmailForPasswordReset() method.
    }

    /**
     * Send the password reset notification.
     *
     * @param  string $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        // TODO: Implement sendPasswordResetNotification() method.
    }

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return string
     */
    public function getAuthIdentifierName()
    {
        // TODO: Implement getAuthIdentifierName() method.
    }

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        // TODO: Implement getAuthIdentifier() method.
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        // TODO: Implement getAuthPassword() method.
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        // TODO: Implement getRememberToken() method.
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string $value
     * @return void
     */
    public function setRememberToken($value)
    {
        // TODO: Implement setRememberToken() method.
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        // TODO: Implement getRememberTokenName() method.
    }
}
abhivachan commented 7 years ago

It works. :-). It is implementation issue and not the framework issue. I am sorry for that.

samirgit commented 7 years ago

@abhivachan how did you make it work?

how did you implement Authenticatable when it is not an interface