protected function superAdminLogin() { $item = $this->params()->fromPost(); $form = new Form\SuperAdminLoginForm(); $viewVariables = array('form' => $form, 'item' => $item); if (!$this->getRequest()->isPost()) { return $viewVariables; } $form->bind($item); if (!$form->isValid()) { return $viewVariables; } $auth = new Auth('Config', 'Session', 'Auth_Admin'); $authResult = $auth->authenticate(array('username' => $item['loginName'], 'password' => $item['inputPassword'])); if ($authResult->isValid()) { $config = $this->getServiceLocator()->get('config'); $auth->saveLoginUser(array('id' => $config['superadmin']['id'], 'userName' => $item['loginName'], 'isSuperAdmin' => true)); $callback = $this->params()->fromPost('callback'); $callback = $callback ? $callback : '/admin/core/dashboard'; $this->redirect()->toUrl($callback); return array(); } switch ($authResult->getCode()) { case Result::FAILURE_IDENTITY_NOT_FOUND: $this->flashMessenger()->addMessage('user-name-failed'); break; case Result::FAILURE_CREDENTIAL_INVALID: $this->flashMessenger()->addMessage('password-failed'); break; default: } return $viewVariables; }
public function indexAction() { $model = new ViewModel(); $this->layout('layout/adminblank'); $model->setTemplate('core/index'); $auth = new Auth('Config', 'Session', 'Auth_Admin'); $auth->getAuthStorage()->clear(); return $this->redirect()->toUrl('/admin/'); }
public function restPutLogin() { $this->layout('layout/adminblank'); $item = $this->params()->fromPost(); $callback = $this->params()->fromPost('callback'); $callback = $callback ? $callback : '/admin/core/dashboard'; $viewVariables = array(); if (!$this->getRequest()->isPost()) { return $viewVariables; } $form = new \User\Form\AdminLoginForm(); $form->bind($item); if ($form->isValid()) { $item = $form->getData(); if ($item['isSuperAdmin']) { $auth = new Auth('Config', 'Session', 'Auth_Admin'); $authResult = $auth->authenticate(array('username' => $item['loginName'], 'password' => $item['inputPassword'])); $config = Api::_()->getConfig(); if ($authResult->isValid()) { $auth->saveLoginUser(array('id' => $config['superadmin']['id'], 'userName' => $item['loginName'], 'isSuperAdmin' => true)); return $this->redirect()->toUrl($callback); } } else { $loginModel = Api::_()->getModel('User\\Model\\Login'); $authResult = $loginModel->loginByPassword($item['loginName'], $item['inputPassword']); if ($authResult->isValid()) { $user = Auth::getLoginUser('Auth_Admin'); if (!isset($user['Roles']) || !in_array('Admin', $user['Roles'])) { $this->getResponse()->setStatusCode(401); $this->flashMessenger()->addMessage('permission-not-enough'); return $this->redirect()->toUrl('/admin/'); } return $this->redirect()->toUrl($callback); } } switch ($authResult->getCode()) { case Result::FAILURE_IDENTITY_NOT_FOUND: $this->flashMessenger()->addMessage('user-name-failed'); break; case Result::FAILURE_CREDENTIAL_INVALID: $this->flashMessenger()->addMessage('password-failed'); break; default: } } else { $item = $form->getData(); } return array('form' => $form, 'item' => $item); }
public function getUserName() { if (!$this->user_name) { $user = \Core\Auth::getLoginUser(); $this->user_name = $user['userName']; } }
public function indexAction() { $user = Auth::getLoginUser(); if (isset($user['isSuperAdmin']) || !$user) { exit; } $adapter = $this->params()->fromQuery('service'); $callback = $this->params()->fromQuery('r'); $version = (int) $this->params()->fromQuery('version'); if (!$adapter) { throw new \Oauth\Exception\InvalidArgumentException(sprintf('No oauth service key found')); } $config = $this->getServiceLocator()->get('config'); $helper = $this->getEvent()->getApplication()->getServiceManager()->get('viewhelpermanager')->get('serverurl'); $importUrl = $helper() . $config['contacts']['import_url_path'] . '?' . http_build_query(array('r' => $callback, 'service' => $adapter)); $import = new \Contacts\ContactsImport($adapter, false, array('cacheConfig' => $config['cache']['contacts_import'])); $contacts = $import->getStorage()->loadContacts(); if ($contacts) { return $this->redirect()->toUrl($callback); } $oauth = new \Oauth\OauthService(); $accessTokenArray = $oauth->getStorage()->getAccessToken(); if (!$accessTokenArray || isset($accessTokenArray['adapterKey']) && $accessTokenArray['adapterKey'] != $adapter) { $url = $helper() . $config['oauth']['request_url_path'] . '?' . http_build_query(array('r' => $importUrl, 'service' => $adapter, 'version' => $version)); return $this->redirect()->toUrl($url); } $import->setAccessToken($accessTokenArray['token']); $contacts = $import->getContacts(); $import->getStorage()->saveContacts($contacts); $accessToken = $oauth->getStorage()->clearAccessToken(); return $this->redirect()->toUrl($callback); }
public function getCreatorId() { if (!$this->user_id) { $user = \Core\Auth::getLoginUser(); $this->user_id = $user['id']; } }
public function getFollowerId() { if (!$this->follower_id) { $user = \Core\Auth::getLoginUser(); $this->follower_id = $user['id']; } }
public function restGetMessages() { $id = $this->params('id'); $userModel = Api::_()->getModel('User\\Model\\User'); $user = $userModel->getUser($id); $query = $this->getRequest()->getQuery(); $form = new Form\ConversationSearchForm(); $form->bind($query); if ($form->isValid()) { $query = $form->getData(); } else { return array('form' => $form, 'items' => array()); } if (!isset($query['author_id'])) { $author = \Core\Auth::getLoginUser(); $query['author_id'] = $author['id']; } $query['user_id'] = $user['id']; $itemModel = Api::_()->getModel('Message\\Model\\Conversation'); $items = $itemModel->setItemList($query)->getConversationList(); $itemModel->markAsRead($items); $items = $items->toArray(array('self' => array('*'), 'join' => array('Sender' => array('userName'), 'Recipient' => array('userName'), 'Message' => array('body')))); $paginator = $itemModel->getPaginator(); return array('user' => $user, 'items' => $items, 'item' => array('Conversation' => array('recipient_id' => $user['id'])), 'query' => $query, 'paginator' => $paginator); }
public static function authority($e) { $router = $e->getRouteMatch(); $moduleNamespace = $router->getParam('moduleNamespace'); if ($moduleNamespace != 'admin') { return true; } $controller = $router->getParam('controllerName'); $action = $router->getParam('action'); if ($controller == 'core' && $action == 'index' || $controller == 'logout' && $action == 'index' || $controller == 'login' && $action == 'index' || $controller == 'reset' && $action == 'index') { return true; } $user = Auth::getLoginUser('Auth_Admin'); if (isset($user['isSuperAdmin'])) { return true; } if (!$user || !isset($user['Roles']) || !in_array('Admin', $user['Roles'])) { $application = $e->getApplication(); $event = $application->getEventManager(); $errorController = 'Core\\Admin\\Controller\\ErrorController'; $router->setParam('controller', $errorController); $router->setParam('action', 'index'); $controllerLoader = $application->getServiceManager()->get('ControllerLoader'); $controllerLoader->setInvokableClass($errorController, $errorController); } return true; }
public function restPostBlog() { $postData = $this->params()->fromPost(); $form = new Form\PostCreateForm(); $form->useSubFormGroup()->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Blog\\Model\\Post'); $user = \Core\Auth::getLoginUser('Auth_Admin'); $postData['user_id'] = $user['id']; $postData['user_name'] = $user['userName']; $postId = $itemModel->setItem($postData)->createPost(); $this->flashMessenger()->addMessage('post-create-succeed'); $this->redirect()->toUrl('/admin/blog/' . $postId); } else { p($postData); p($form->getMessages()); //p($form->getElements(), 1); foreach ($form->getFieldsets() as $fieldset) { // p($fieldset->getMessages()); // p($fieldset->getElements()); } } return array('form' => $form, 'post' => $postData); }
public function indexAction() { $user = Auth::getLoginUser(); if (isset($user['isSuperAdmin']) || !$user) { exit; } $callback = $this->params()->fromQuery('r'); $service = $this->params()->fromQuery('service'); $emails = $this->params()->fromPost('email'); if (!$emails) { exit; } $config = $this->getServiceLocator()->get('config'); $helper = $this->getEvent()->getApplication()->getServiceManager()->get('viewhelpermanager')->get('serverurl'); $url = $helper() . '/register/'; if (!isset($config['contacts']['invite_mail'])) { exit; } $inviteModel = Api::_()->getModel('Contacts\\Model\\Invite'); $inviteModel->setUser($user); $inviteModel->setRegUrl($url); $params['emails'] = $emails; $params['subject'] = $config['contacts']['invite_mail']['subject']; $params['template'] = $config['contacts']['invite_mail']['template']; $params['templatePath'] = $config['contacts']['invite_mail']['templatePath']; $inviteModel->sendInvite($params); foreach ($emails as $email) { $this->removeContacts($service, $email); } return $this->redirect()->toUrl($callback); }
public function syncAction() { $serviceKey = $this->params()->fromQuery('service'); $serviceType = $this->params()->fromQuery('type'); $content = $this->params()->fromQuery('content'); $user = \Core\Auth::getLoginUser(); $userId = $user['id']; $serviceKey = ucfirst(strtolower($serviceKey)); $serviceType = ucfirst(strtolower($serviceType)); $this->changeViewModel('json'); if (!$userId || !$content) { return new JsonModel(); } $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken'); $dataClass = $itemModel->getItem()->getDataClass(); $item = $dataClass->where(function ($where) use($serviceKey, $serviceType, $userId) { $where->equalTo('adapterKey', strtolower($serviceKey)); $where->equalTo('tokenStatus', 'active'); $where->equalTo('version', $serviceType); $where->equalTo('user_id', $userId); return $where; })->find('one'); $item = (array) $item; if (!$item) { return new JsonModel(); } $webserice = WebserviceFactory::factory($serviceType . $serviceKey, $item, $this->getServiceLocator()); $adapter = $webserice->getAdapter(); $feedApi = $adapter->uniformApi('Feed'); $feedApi->setUserId($item['remoteUserId']); $feed = $feedApi->createFeed(array('content' => $content)); return new JsonModel(array('data' => $feed)); }
public function __construct($service, $config) { $this->setCacheConfig($config); $this->initCache(); $user = Auth::getLoginUser(); $this->setUser($user); $this->service = $service; }
public function getSenderId() { if (!$this->sender_id) { $user = \Core\Auth::getLoginUser(); return $this->sender_id = $user['id']; } else { return $this->sender_id; } }
public function settingAction() { $request = $this->getRequest(); $user = Auth::getLoginUser(); $itemModel = Api::_()->getModel('User\\Model\\User'); $item = $itemModel->getUser($user['id']); $item = $item->toArray(array('self' => array('*'), 'join' => array('Profile' => array('*'), 'Roles' => array('*')))); return array('item' => $item); }
protected function check_access($privs) { if (!Auth::app()->can($privs)) { $action = 'action_access_err'; $conrtroller = new Msg(); $conrtroller->request($action, $this->params); die; } }
public function __construct() { $this->title = ''; $this->content = ''; $this->left = ''; $this->base_template = 'v_main.php'; $this->active_user = Auth::app()->user(); // авторизованный пользователь $this->admin_link = in_array($this->active_user['id_role'], ['1', '3']); // только для админа и модератора }
public function isfriendAction() { $this->changeViewModel('json'); $user = \Core\Auth::getLoginUser(); if (!$user) { return new JsonModel(array('item' => null)); } $selectQuery = array('from_user_id' => $this->params()->fromQuery('user_id'), 'to_user_id' => $user['id']); $itemModel = Api::_()->getModel('User\\Model\\Friend'); $item = $itemModel->setItemList($selectQuery)->getFriendList()->toArray(); return new JsonModel(array('item' => $item)); }
public function onlineAction() { $this->changeViewModel('json'); $user = Auth::getLoginUser(); if ($user) { $itemModel = Api::_()->getModel('User\\Model\\User'); $dataClass = $itemModel->getItem()->getDataClass(); $dataClass->where(array('id' => $user['id']))->save(array('onlineStatus' => 'online', 'lastFreshTime' => \Eva\Date\Date::getNow())); return new JsonModel(); } return new JsonModel(); }
public function indexAction() { $callback = $this->params()->fromQuery('callback'); if (!$callback && $this->getRequest()->getServer('HTTP_REFERER')) { $callback = $this->getRequest()->getServer('HTTP_REFERER'); } $callback = $callback ? $callback : '/'; $model = new ViewModel(); $auth = Auth::factory(); $auth->getAuthStorage()->clear(); $this->cookie()->clear('realm'); return $this->redirect()->toUrl($callback); }
public function prepareData($data) { if (!$data['page']) { $data['page'] = 1; } if (!$data['order']) { $data['order'] = 'timedesc'; } if (!$data['author_id']) { $user = \Core\Auth::getLoginUser(); $data['author_id'] = $user['id']; } return $data; }
public function restDeleteNewsletter() { $postData = $this->params()->fromPost(); $callback = $this->params()->fromPost('callback'); $callback = $callback ? $callback : '/home/'; $user = Auth::getLoginUser(); $userModel = Api::_()->getModel('User\\Model\\User'); $mine = $userModel->getUser($user['id']); if (!$mine) { exit; } $postTable = Api::_()->getDbTable('Core\\DbTable\\Newsletters'); $postTable->where(array('user_id' => $mine['id']))->remove(); $this->redirect()->toUrl($callback); }
public function restPostNotification() { $request = $this->getRequest(); $postData = $request->getPost(); $form = new Form\NotificationCreateForm(); $form->useSubFormGroup()->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Notification\\Model\\Notification'); $user = \Core\Auth::getLoginUser('Auth_Admin'); $notificationId = $itemModel->setItem($postData)->createNotification(); $this->flashMessenger()->addMessage('notification-create-succeed'); $this->redirect()->toUrl('/admin/notification/' . $notificationId); } else { } return array('form' => $form, 'post' => $postData); }
public function restPostGroup() { $request = $this->getRequest(); $postData = $request->getPost(); $form = new Form\GroupCreateForm(); $form->useSubFormGroup()->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Group\\Model\\Group'); $user = \Core\Auth::getLoginUser('Auth_Admin'); $postData['user_id'] = $user['id']; $groupId = $itemModel->setItem($postData)->createGroup(); $this->flashMessenger()->addMessage('group-create-succeed'); $this->redirect()->toUrl('/admin/group/' . $groupId); } else { } return array('form' => $form, 'post' => $postData); }
public function restPostEvent() { $postData = $this->params()->fromPost(); $form = new Form\EventCreateForm(); $form->useSubFormGroup()->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Event\\Model\\Event'); $user = \Core\Auth::getLoginUser('Auth_Admin'); $postData['user_id'] = $user['id']; $postData['user_name'] = $user['userName']; $eventId = $itemModel->setItem($postData)->createEventdata(); $this->flashMessenger()->addMessage('event-create-succeed'); $this->redirect()->toUrl('/admin/event/' . $eventId); } else { } return array('form' => $form, 'post' => $postData); }
public function restDeleteMessage() { $postData = $this->params()->fromPost(); $callback = $this->params()->fromPost('callback', '/message/messages/'); $form = new Form\ConversationDeleteForm(); $form->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Message\\Model\\Conversation'); $conversation = $itemModel->getConversation($postData['id'])->toArray(); $user = \Core\Auth::getLoginUser(); if ($user['id'] != $conversation['author_id']) { exit; } $itemModel->setItem($postData)->removeConversation(); $this->redirect()->toUrl($callback); } else { return array('conversation' => $postData); } }
public function restPostComment() { $postData = $this->params()->fromPost(); $form = new Form\CommentCreateForm(); $form->useSubFormGroup()->bind($postData); if ($form->isValid()) { $postData = $form->getData(); $itemModel = Api::_()->getModel('Blog\\Model\\Comment'); $user = \Core\Auth::getLoginUser('Auth_Admin'); if (!$postData['user_id']) { $postData['user_id'] = $user['id']; } if (!$postData['user_name']) { $postData['user_name'] = $user['userName']; } $itemId = $itemModel->setItem($postData)->createComment(); $this->redirect()->toUrl('/admin/blog/comment/' . $itemId); } else { } return array('form' => $form, 'item' => $postData); }
public function beforeBind($data) { $user = \Core\Auth::getLoginUser(); $data['follower_id'] = $user['id']; return $data; }
/** * Check access rights * @param array $mvcData */ private function _isAclAllow(array $mvcData) { $acl = \Core\Acl\Acl::getInstance(); $auth = \Core\Auth::getInstance(); if ($auth->hasIdentity()) { $data = $auth->getIdentity(); $role = $data['title']; } else { $role = 'guest'; } return $acl->isAllow($role, implode(':', $mvcData)); }
public function indexAction() { if (!\Core\Auth::getInstance()->hasIdentity()) { $this->_redirect('/main/user/login'); } }