psecio / gatekeeper

Gatekeeper: An Authentication & Authorization Library
367 stars 23 forks source link

How to change a password? #27

Closed Ser5 closed 9 years ago

Ser5 commented 9 years ago

This code gives me false as the result:

use \Psecio\Gatekeeper\Gatekeeper;
Gatekeeper::disableThrottle();

$user = Gatekeeper::findUserById(1);
$password = 'aaaaaa';
$user->password = $password;
$user->save();
$result = Gatekeeper::authenticate(array('username' => $user->username, 'password' => $password));
var_dump($user->id, $result);
Ser5 commented 9 years ago

Well, I have found that I can save a model by calling

Gatekeeper::getDatasource()->save($user);

But not sure if this a kind of hack or the right way to work. The documentation doesn't mention any save() methods.

enygma commented 9 years ago

Yeah, this data source separation was done because there were issues with serializing a model with a PDO connection embedded in it. Seems like the save method could be overridden on the models to get the current data source and mimic the save() call directly on the model though.

enygma commented 9 years ago

An update in 685a9c116 makes it so that you can call save directly on the model instance and have it work as expected.