/** * Saves a user object within the current application. * * @param UmgtUser $user current user. * * @return int The id of the user. * * @author Christian Achatz * @version * Version 0.1, 15.06.2008<br /> * Version 0.2, 23.06.2009 (Introduced a generic possibility to create the display name.)<br /> * Version 0.3, 20.09.2009 (Bug fix for bug 202. Password was hased twice on update.)<br /> * Version 0.4, 27.09.2009 (Bug fix for bug related to 202. Password for new user was not hashed.)<br /> */ public function saveUser(UmgtUser &$user) { $orm = $this->getORMapper(); // check, whether user is an existing user, and yes, resolve the // password conflict, described under http://forum.adventure-php-framework.org/viewtopic.php?f=8&t=202 $userId = $user->getObjectId(); $password = $user->getPassword(); if ($userId !== null && $password !== null) { $storedUser = $orm->loadObjectByID('User', $userId); /* @var $storedUser UmgtUser */ // In case, the stored password is different to the current one, // hash the password. In all other cases, the password would be // hashed twice! if ($storedUser->getPassword() != $password) { $user->setPassword($this->createPasswordHash($password, $user)); } else { $user->deletePassword(); } } else { // only create password for not empty strings! if (!empty($password)) { $user->setPassword($this->createPasswordHash($password, $user)); } } // set display name $user->setDisplayName($this->getDisplayName($user)); // save the user and return it's id $app = $this->getCurrentApplication(); $user->addRelatedObject('Application2User', $app); return $orm->saveObject($user); }