Exemplo n.º 1
0
 public function indexAction()
 {
     if (!($user = $this->authenticationService->getUser())) {
         throw new UnauthorizedAccessException('You must be logged in.');
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $this->form->bind($user);
     if ($request->isPost()) {
         $this->form->setData($request->getPost()->toArray());
         if ($this->form->isValid()) {
             $this->repositoryService->store($user);
             $vars = array('valid' => true);
             $this->notification()->success('Password successfully changed');
         } else {
             // form is invalid
             $vars = array('valid' => false);
             // @TODO the messages are distributed to the hierarchy of the subElements, either we reduce that to flat plain text, or we make a message handling in JS
             $messages = $this->form->getMessages();
             $this->notification()->error('Password could not be changed');
         }
     }
     $vars['form'] = $this->form;
     if ($request->isXmlHttpRequest()) {
         return new JsonModel($vars);
     }
     return $vars;
 }