/** * Возвращает информацию о текущем пользователе * * @return array */ public function getCurrentUserInfo() { $User = new Phorm_User($this->_bootstrap); $token = $this->_bootstrap->getResource('Request')->getCookie('token'); /** * Проверяем негостевые данные в сессии */ if (isset($this->_usersession->UserData) && $this->_usersession->UserData['userid'] > 0) { return $this->_usersession->UserData; /** * Проверяем токен в куках */ } elseif ($token && ($UserData = $User->getUserInfo(array('tokenauth' => $token)))) { $User->saveUserInfo(array('userid' => $UserData['userid'], 'lastvisit' => time(), 'lastip' => $this->_request->getClientIp())); return $UserData; /** * Гостевые данные из существующий сессии */ } elseif (isset($this->_usersession->UserData)) { return $this->_usersession->UserData; /** * Гостевые данные при новой сессии без токена */ } else { return $User->getUserInfo(array('userid' => 0)); } }
/** * Редактирование собственного профиля * * @return void */ public function profileAction() { if ($this->_usersession->UserData['userid'] > 0 && ($UserInfo = $this->User->getUserInfo(array('userid' => $this->_usersession->UserData['userid'])))) { $form = $this->User->getProfileForm(); $form->setDefaults($UserInfo); if ($this->_request->isPost()) { $FormData = $this->_request->getPost(); // Нередактируемые поля $FormData['userid'] = $UserInfo['userid']; $FormData['username'] = $UserInfo['username']; if ($form->isValid($FormData)) { $FormData = $form->getValues(); unset($FormData['signed'], $FormData['lastvisit']); if ($FormData = $this->User->saveUserInfo($FormData)) { $this->User->_usersession->UserData = $this->User->getUserInfo(array('userid' => $FormData['userid'])); return $this->composeSuccessMessage('Изменения внесены', '/users/profile/'); } else { $this->composeTransactionErrorMessage($this->User->_errors); } } } $this->view->assign('Form', $form); } else { return $this->composeErrorMessage('Пользователь с указанным Id не найден', '/users/'); } }
/** * Пакетное управление доступом к MVC-ресурсам * * @return void */ public function aclAction() { $User = new Phorm_User(); if ($this->_request->isPost()) { $FormData = $this->_request->getPost(); if (isset($FormData['acl']) && is_array($FormData['acl'])) { if ($this->Mvc->updateRolesAcl($FormData['acl'])) { $this->_usersession->UserData = $User->getUserInfo(array('userid' => $this->_usersession->UserData['userid'])); $this->view->assign("Success", array($this->_translate->_('Изменения внесены'))); } else { $this->composeTransactionErrorMessage($this->Mvc->_errors); } } } $this->view->assign('Resources', $this->Mvc->getModulesControllersActions()); $this->view->assign('AclList', $this->Mvc->getAclList()); $this->view->assign('Roles', $User->getRolesList()); }
/** * Редактирование раздела * * @return void */ public function editAction() { if (isset($this->_params['categoryid']) && ($CategoryInfo = $this->Categories->getCategoryInfo($this->_params['categoryid']))) { if ($this->Categories->isAllowedAction('edit', $CategoryInfo['categoryid'])) { $form = $this->Categories->getCategoryForm($CategoryInfo['categoryid'], 'edit'); $form->setDefaults($CategoryInfo); if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { if ($this->Categories->saveCategoryForm($form, $CategoryInfo['categoryid'])) { $User = new Phorm_User(); $this->_usersession->UserData = $User->getUserInfo(array('userid' => $this->_usersession->UserData['userid'])); return $this->composeSuccessMessage('Изменения внесены', '/control/categories/view/categoryid/' . $CategoryInfo['categoryid'] . '/tree/reload/'); } else { $this->composeTransactionErrorMessage($this->Categories->_errors); } } $this->view->assign("Form", $form); } else { return $this->composeErrorMessage('Недостаточно прав для внесения изменений', '/control/categories/view/categoryid/' . $CategoryInfo['categoryid'] . '/'); } } else { return $this->composeErrorMessage('Раздел с указанным Id не найден', '/control/categories/'); } }