예제 #1
0
 public function submitAction()
 {
     // Do we have a user?
     if (!$this->auth->hasIdentity()) {
         $response = $this->getResponse();
         $response->setStatusCode(401);
         $viewModel = new ViewModel();
         $viewModel->setTemplate('phly-peep/peep/401');
         return $viewModel;
     }
     $identity = $this->auth->getIdentity();
     if (!$identity instanceof User) {
         throw new \DomainException('Unknown authenticated user type encountered');
     }
     $peep = new Model\PeepEntity();
     $form = Model\PeepForm::factory($peep);
     $request = $this->getRequest();
     $data = $request->getPost();
     $data['username'] = $identity->getUsername();
     $data['email'] = $identity->getEmail();
     $data['display_name'] = $identity->getDisplayName();
     $data['timestamp'] = $_SERVER['REQUEST_TIME'];
     $form->setData($data);
     $form->setValidationGroup('peep_text', 'username', 'email', 'display_name', 'timestamp', 'secure');
     if (!$form->isValid()) {
         $viewModel = new ViewModel(array('form' => $form));
         $viewModel->setTemplate('phly-peep/peep/form-error');
         return $viewModel;
     }
     $this->service->insertPeep($peep);
     return $this->redirect()->toRoute('phly-peep/user', array('username' => $identity->getUsername()));
 }
예제 #2
0
 public function __invoke($form = null, $template = 'phly-peep/peep/form')
 {
     if (!$this->auth || !$this->auth->hasIdentity()) {
         return $this->view->render('phly-peep/peep/register');
     }
     if (null === $form) {
         $form = Model\PeepForm::factory();
     }
     return $this->view->render($template, array('form' => $form));
 }