private function readUser() { $this->m_preview = false; $container = \Zend_Registry::get('container'); $userService = $container->getService('user'); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $user = $userService->find($auth->getIdentity()); if (!empty($user)) { $this->m_user = new MetaUser($user); $this->m_preview = CampRequest::GetVar('preview') === 'on' && $this->m_user->isAdmin(); if (!$this->m_preview && CampRequest::GetVar('preview') === 'on' && $container->getService('blog')->isBlogger($user)) { $lang = \Language::GetLanguageIdByCode(CampRequest::GetVar('language')); $article = new \Article($lang, CampRequest::GetVar('articleNo')); $this->m_preview = $container->getService('blog')->isUsersArticle($article, $user); } } } elseif (!empty($_SERVER['REMOTE_ADDR'])) { // empty in cli $ipUsers = IPAccess::GetUsersHavingIP($_SERVER['REMOTE_ADDR']); if (!empty($ipUsers)) { $user = $userService->find($ipUsers[0]->getUserId()); $this->m_user = new MetaUser($user); } } }
public function loginAction() { $this->getHelper('contextSwitch')->addActionContext('login', 'json')->initContext(); $translator = Zend_Registry::get('container')->getService('translator'); $request = $this->getRequest(); if ($request->isPost()) { $params = $request->getParams(); $adapter = $this->_helper->service('auth.adapter'); $adapter->setEmail($params['email'])->setPassword($params['password']); $result = $this->auth->authenticate($adapter); if ($result->getCode() == Zend_Auth_Result::SUCCESS) { $user = Zend_Registry::get('container')->getService('user')->getCurrentUser(); $metaUser = new \MetaUser($user); $width = array_key_exists("imageWidth", $params) ? $params['imageWidth'] : 80; $height = array_key_exists("imageHeight", $params) ? $params['imageHeight'] : 80; $specification = array_key_exists("imageSpecification", $params) ? $params['imageSpecification'] : 'fit'; $this->view->userData = array('realName' => $user->getRealName(), 'username' => $user->getUsername(), 'avatar' => $metaUser->image($width, $height, $specification)); $this->view->response = 'OK'; } else { $this->view->response = $translator->trans('Login failed.'); } } }
/** * Get user by given id * * @ApiDoc( * statusCodes={ * 200="Returned when successful", * 404="Returned when the user is not found", * }, * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="User id"}, * {"name"="image_type", "dataType"="string", "required"=false, "description"="User image specification (e.g. crop, fit)"}, * {"name"="image_width", "dataType"="integer", "required"=false, "description"="User image width"}, * {"name"="image_height", "dataType"="integer", "required"=false, "description"="User image height"}, * }, * output="\Newscoop\Entity\User" * ) * * @Route("/users/{id}.{_format}", defaults={"_format"="json"}, options={"expose"=true}) * @Method("GET") * @View(serializerGroups={"list"}) * * @return array */ public function getUserAction(Request $request, $id) { $em = $this->container->get('em'); $imageType = $request->get('image_type'); $imageHeight = $request->get('image_height'); $imageWidth = $request->get('image_width'); $user = $em->getRepository('Newscoop\\Entity\\User')->getOneActiveUser($id)->getOneOrNullResult(); if (!$user) { throw new NotFoundHttpException('Result was not found.'); } $metaUser = new \MetaUser($user); $user->setImage($metaUser->image(is_numeric($imageWidth) ? $imageWidth : 80, is_numeric($imageHeight) ? $imageHeight : 80, !is_numeric($imageType) && is_string($imageType) ? $imageType : 'crop')); return $user; }