/** * The put action handles PUT requests and receives an 'id' parameter; it * should update the server resource state of the resource identified by * the 'id' value. */ public function putAction() { $id = intval(filter_var($this->_request->getParam('id'), FILTER_VALIDATE_INT)); $data = json_decode($this->_request->getRawBody(), true); if ($id && !empty($data)) { if (!Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_USERS) && $id !== $this->_sessionHelper->getCurrentUser()->getId()) { $this->_error(self::REST_STATUS_FORBIDDEN); } $user = Application_Model_Mappers_UserMapper::getInstance()->find($id); if ($user instanceof Application_Model_Models_User) { Application_Model_Mappers_UserMapper::getInstance()->loadUserAttributes($user); foreach ($data as $attribute => $value) { $setter = 'set' . ucfirst(strtolower($attribute)); if (method_exists($user, $setter)) { $user->{$setter}($value); } else { $user->setAttribute($attribute, $value); } } $user->setPassword(false); Application_Model_Mappers_UserMapper::getInstance()->save($user); return array('status' => 'ok'); } } }
protected function _load() { if (empty($this->_options)) { throw new Exceptions_SeotoasterWidgetException('No options provided'); } if (is_numeric(reset($this->_options))) { $userId = array_shift($this->_options); $this->_user = Application_Model_Mappers_UserMapper::getInstance()->find($userId); if (is_null($this->_user)) { return ''; } } elseif ($this->_sessionHelper->getCurrentUser()->getRoleId() === Tools_Security_Acl::ROLE_GUEST) { return ''; } else { $this->_user = $this->_sessionHelper->getCurrentUser(); } $this->_user->loadAttributes(); if (Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_USERS) || $this->_user->getId() === $this->_sessionHelper->getCurrentUser()->getId()) { $this->_editableMode = true; Zend_Layout::getMvcInstance()->getView()->headScript()->appendFile($this->_websiteHelper->getUrl() . 'system/js/internal/user-attributes.js'); } $method = strtolower(array_shift($this->_options)); try { return $this->{'_render' . ucfirst($method)}(); } catch (Exception $e) { return '<b>Method ' . $method . ' doesn\'t exist</b>'; } }