/** * Signup if not logged in * * @return void */ public function indexAction() { $this->layout('layout/signup'); $viewData = array(); $signupForm = new SignupForm(); $signupForm->setAttribute('action', $this->url()->fromRoute('users-signup')); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()->toArray(); $signupForm->setInputFilter(User::getInputFilter()); $signupForm->setData($data); if ($signupForm->isValid()) { $files = $request->getFiles()->toArray(); $data = $signupForm->getData(); $data['avatar'] = $files['avatar']['name'] != '' ? $files['avatar']['name'] : null; if ($data['avatar'] !== null) { $size = new Size(array('max' => 2048000)); $isImage = new IsImage(); $filename = $data['avatar']; $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setValidators(array($size, $isImage), $filename); if (!$adapter->isValid($filename)) { $errors = array(); foreach ($adapter->getMessages() as $key => $row) { $errors[] = $row; } $signupForm->setMessages(array('avatar' => $errors)); } $destPath = 'data/tmp/'; $adapter->setDestination($destPath); $fileinfo = $adapter->getFileInfo(); preg_match('/.+\\/(.+)/', $fileinfo['avatar']['type'], $matches); $newFilename = sprintf('%s.%s', sha1(uniqid(time(), true)), $matches[1]); $adapter->addFilter('File\\Rename', array('target' => $destPath . $newFilename, 'overwrite' => true)); if ($adapter->receive($filename)) { $data['avatar'] = base64_encode(file_get_contents($destPath . $newFilename)); if (file_exists($destPath . $newFilename)) { unlink($destPath . $newFilename); } } } unset($data['repeat_password']); unset($data['csrf']); unset($data['register']); $response = ApiClient::registerUser($data); if ($response['result'] == true) { $this->flashMessenger()->addMessage('Account created!'); return $this->redirect()->toRoute('wall', array('username' => $data['username'])); } } } $viewData['signupForm'] = $signupForm; return $viewData; }
/** * Performs an authentication attempt * * @return \Zend\Authentication\Result * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface * If authentication cannot be performed */ public function authenticate() { $result = ApiClient::authenticate(array('username' => $this->username, 'password' => $this->password)); if ($result['result'] === true) { $hydrator = new ClassMethods(); $user = $hydrator->hydrate(ApiClient::getUser($this->username), new User()); $response = new Result(Result::SUCCESS, $user, array('Authentication successful.')); } else { $response = new Result(Result::FAILURE, NULL, array('Invalid credentials.')); } return $response; }
/** * Performs an authentication attempt * * @return \Zend\Authentication\Result * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface * If authentication cannot be performed */ public function authenticate() { $result = ApiClient::authenticate(array('username' => $this->username, 'password' => $this->password)); if (array_key_exists('access_token', $result) && !empty($result['access_token'])) { $hydrator = new ClassMethods(); $user = $hydrator->hydrate(ApiClient::getUser($this->username), new User()); $session = new Container('oauth_session'); $session->setExpirationSeconds($result['expires_in']); $session->accessToken = $result['access_token']; $response = new Result(Result::SUCCESS, $user, array('Authentication successful.')); } else { $response = new Result(Result::FAILURE, NULL, array('Invalid credentials.')); } return $response; }
public function indexAction() { $viewData = array(); $username = $this->params()->fromRoute('username'); $this->layout()->username = $username; $response = ApiClient::getWall($username); if ($response !== FALSE) { $hydrator = new ClassMethods(); $user = $hydrator->hydrate($response, new User()); } else { $this->getResponse()->setStatusCode(404); return; } $viewData['profileData'] = $user; return $viewData; }
/** * Method to process a simple form * User by createStatus() and createLink() * * @param Zend\Form\Form $form * @param string $user * @param array $data * @return mixed */ protected function processSimpleForm($form, $user, array $data) { $form->setData($data); if ($form->isValid()) { $data = $form->getData(); $data['user_id'] = $user->getId(); unset($data['submit']); unset($data['csrf']); $response = ApiClient::postWallContent($user->getUsername(), $data); return $response['result']; } return $form; }
/** * Unsubscribe a user from a specific feed * * @return void */ public function unsubscribeAction() { $username = $this->params()->fromRoute('username'); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()->toArray(); $response = ApiClient::removeFeedSubscription($username, $data['feed_id']); if ($response['result'] == TRUE) { $this->flashMessenger()->addMessage('Unsubscribed successfully!'); } else { return $this->getResponse()->setStatusCode(500); } } return $this->redirect()->toRoute('feeds', array('username' => $username)); }