Example #1
0
 /**
  * @param  \Secretary\Entity\Key  $key
  * @param  \Secretary\Entity\User $user
  * @return \Secretary\Entity\Key
  */
 public function saveKey(KeyEntity $key, UserEntity $user, $pubKey)
 {
     $key->setPubKey($pubKey);
     $key->setUserId($user->getId());
     $key->setUser($user);
     $this->em->persist($key);
     $this->em->flush();
     return $key;
 }
 /**
  * {@inheritDoc}
  */
 public function __call($method, $args)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__call', array($method, $args));
     return parent::__call($method, $args);
 }
Example #3
0
 /**
  * Process add form
  *
  * @return \Zend\View\Model\ViewModel
  * @throws \LogicException If creation of key fails
  */
 public function addAction()
 {
     $keyRecord = $this->getKeyService()->fetchKey($this->identity->getId());
     if (!empty($keyRecord)) {
         return $this->redirect()->toRoute('secretary/default', array('controller' => 'key', 'action' => 'index'));
     }
     $action = $this->params()->fromPost('mode', 'create');
     if (!in_array($action, $this->availableActions)) {
         $action = 'create';
     }
     $form = $this->getKeyForm();
     $form->setMode($action);
     $viewModel = new ViewModel();
     $msg = array('error', 'An error occurred');
     $viewVars = array('keyRecord' => $keyRecord, 'keyForm' => $form, 'msg' => $msg, 'activeMode' => $action);
     if ($this->getRequest()->isPost()) {
         $newKeyRecord = new KeyEntity();
         if ($action == 'create') {
             $form->setInputFilter($newKeyRecord->getInputFilter());
         }
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             $values = $form->getData();
             // Generate Keys
             $successText = '';
             $keys = array();
             if ($action == 'create') {
                 $passphrase = $values['passphrase'];
                 try {
                     $keys = $this->getCryptService()->createPrivateKey($passphrase);
                 } catch (\Exception $e) {
                     throw new \LogicException($e->getMessage(), 0, $e);
                 }
                 $viewVars['privKey'] = $keys['priv'];
                 $successText = 'Your key was created successfully';
             } elseif ($action == 'add') {
                 try {
                     $this->getCryptService()->validatePublicKey($values['public_key']);
                 } catch (\Exception $e) {
                     // Error
                     $viewVars['msg'] = array('error', $this->translator->translate('Validation of provided key failed!'));
                     $viewModel->setVariables($viewVars);
                     $viewModel->setTemplate('secretary/key/index');
                     return $viewModel;
                 }
                 $keys['pub'] = $values['public_key'];
                 $successText = 'Your key was added successfully';
             }
             // Save Data
             $this->getKeyService()->saveKey($newKeyRecord, $this->identity, $keys['pub']);
             // Upgrade User to KeyUser Role
             $this->userService->updateUserToKeyRole($this->identity);
             // Success
             $viewVars['msg'] = array('success', $this->translator->translate($successText));
             $viewModel->setVariables($viewVars);
             $viewModel->setTemplate('secretary/key/success');
             return $viewModel;
         }
     }
     $viewModel->setVariables($viewVars);
     $viewModel->setTemplate('secretary/key/index');
     return $viewModel;
 }