public function update(Controller_Action $controller, $user_data) { $result = NULL; if ($this->user->loadById($user_data["userid"])) { //we should not receive this field under ldap if (isset($user_data["oldpassword"])) { $controller->setError("Invalid password."); return $result; } if (!$controller->getErrorFlag()) { foreach ($user_data as $key => $value) { if ($key != "userid" && $key != "oldpassword" && $key != "newpassword") { $method = 'set' . DataObject::camelize($key); $this->user->{$method}($value); } //we should not receive this field under ldap if ($key == "newpassword") { $controller->setError("Invalid password."); return $result; } } try { if ($this->user->save()) { $result = true; } else { $controller->setError("Unable to save new user data."); } } catch (Exception $e) { $controller->setError($e->getMessage()); } } } else { $controller->setError("User doesn't exist."); } return $result; }
/** * Loads data into instance * * @param mixed $data Either an instance of stdClass or an associative array * * @throws Exception * @throws User_Exception * @return boolean */ protected function load($data) { if (is_object($data) && $data instanceof stdClass) { foreach ($this->getColumns() as $col) { if ($col == 'password') { // directly set password value $this->password = $data->{$col}; continue; } $method = 'set' . DataObject::camelize($col); $this->{$method}($data->{$col}); } return true; } else { throw new User_Exception('Invalid parameter.'); } }