Ok, solved it myself, seeing as this is not a very active topic.
The problem was combining ardents autohydration feature and the unique requirement to retain the old password, if no new one is given. Because ardent autohydrates on validate()
AND save()
, there was no way to prevent autohydrating empty passwords too. First, I tried to change the Input array and overwrite it with the old password, but then I simply turned off the autohydration for the user model:
class User extends Ardent implements UserInterface, RemindableInterface {
public $forceEntityHydrationFromInput = false;
public $autoHydrateEntityFromInput = false;
This is the edit action on POST:
public function postEdit($id)
{
// manually insert the input
$user = new User(Input::all());
// validate the user with special rules (password not required)
if($user->validate(User::$updateRules)) {
// get user from database and fill with input except password
$user = User::find($id);
$user->fill(Input::except('password'));
// fill in password if it is not empty
// will flag the pw as dirty, which will trigger rehashing on save()
if(!empty(Input::get('password')))
$user->password = Input::get('password');
if($user->save())
return Redirect::action('UsersController@getIndex')
->with('success', Lang::get('Änderungen gespeichert'));
}
return Redirect::action('UsersController@getEdit', $id)
->with('error', Lang::get('Bitte Eingaben überprüfen'))
->withErrors($user->errors())
->withInput(Input::except('password'));
}