コード例 #1
0
 public function signupAction()
 {
     $account = new Account();
     $accountForm = new AccountForm($account);
     $this->view->accountForm = $accountForm;
     $user = new User();
     $userForm = new UserForm($user);
     $this->view->userForm = $userForm;
     $this->view->setVar("tab", 0);
     if ($this->request->isPost()) {
         try {
             $this->db->begin();
             $accountForm->bind($this->request->getPost(), $account);
             $userForm->bind($this->request->getPost(), $user);
             $idAccountplan = $accountForm->getValue('idAccountplan');
             $idAccounttype = $accountForm->getValue('idAccounttype');
             $city = $accountForm->getValue('city');
             $pass1 = $userForm->getValue('pass1');
             $pass2 = $userForm->getValue('pass2');
             $email = $this->request->getPost('email');
             $this->validateEqualsPassword($pass1, $pass2);
             $this->validateFields(array($idAccounttype, $idAccountplan, $city), array("Debes seleccionar un tipo de cuenta", "Debes seleccionar un plan de pago, recuerda que tenemos algunos gratuitos", "Debes seleccionar una ciudad"));
             if ($this->saveAccount($account, $accountForm, $userForm)) {
                 if ($this->saveUser($user, $account)) {
                     $file = $_FILES['avatar'];
                     $ext = explode("/", $file['type']);
                     $file['newName'] = "{$user->idUser}.{$ext[1]}";
                     $dir = $this->uploader->user_avatar_dir . "/" . $user->idUser . "/images/avatar/";
                     $uploader = new \Sayvot\Misc\Uploader();
                     $uploader->setExtensionsAllowed(array("png", "jpg", "jpeg"));
                     $uploader->setFile($file);
                     $uploader->setMaxSizeSupported($this->uploader->images_max_size);
                     $uploader->setDir($dir);
                     $uploader->validate();
                     $uploader->upload();
                     if ($this->saveCredential($user, $email, $pass1)) {
                         $this->db->commit();
                         $pe = new \Sayvot\Misc\ParametersEncoder();
                         $link = $pe->encodeLink("account/verify", array($account->idAccount, $user->idUser));
                         $this->flashSession->warning($link);
                         return $this->response->redirect("session/login");
                     }
                 }
             }
         } catch (InvalidArgumentException $ex) {
             $this->flashSession->error($ex->getMessage());
             $this->db->rollback();
         } catch (Exception $ex) {
             $this->db->rollback();
             $this->flashSession->error("Ha ocurrido un error, por favor contacta al administrador");
             $this->logger->log("Exception while creating account: " . $ex->getMessage());
             $this->logger->log($ex->getTraceAsString());
         }
     }
 }
コード例 #2
0
 public function editAction($id)
 {
     $account = Account::findFirst(array("conditions" => "idAccount = ?1", "bind" => array(1 => $id)));
     if (!$account) {
         $this->flashSession->warning('La cuenta que desea editar no existe, por favor valide la información');
         return $this->response->redirect('account');
     }
     $form = new AccountForm($account);
     if ($this->request->isPost()) {
         $form->bind($this->request->getPost(), $account);
         $status = $form->getValue('status2');
         $account->status = empty($status) || !$status ? 0 : 1;
         $account->updated = time();
         if ($form->isValid() && $account->save()) {
             $this->flashSession->success("Se ha editado la cuenta exitosamente");
             return $this->response->redirect("account");
         }
         foreach ($account->getMessages() as $msg) {
             $this->flashSession->error($msg);
         }
     }
     $this->view->AccountForm = $form;
     $this->view->setVar("account", $account);
 }
コード例 #3
0
 public function updateAction($id)
 {
     $account = Account::findFirst(array('conditions' => "idAccount = ?0", 'bind' => array($id)));
     $this->validateModel($account, "No existe una cuenta con el id: {$id}", "account");
     $accountForm = new AccountForm($account);
     $this->view->accountForm = $accountForm;
     $this->view->setVar("account", $account);
     if ($this->request->isPost()) {
         try {
             $accountForm->bind($this->request->getPost(), $account);
             $status = $accountForm->getValue('st');
             $account->status = empty($status) ? 0 : 1;
             if ($this->saveModel($currency, "Se ha editado cuenta <em><strong>{$account->name}</strong></em> exitosamente")) {
                 return $this->response->redirect("account");
             }
         } catch (InvalidArgumentException $ex) {
             $this->flashSession->error($ex->getMessage());
         } catch (Exception $ex) {
             $this->flashSession->error("Ha ocurrido un error, por favor contacta al administrador");
             $this->logger->log($ex->getMessage());
             $this->logger->log("Exception while creating currency: " . $ex->getTraceAsString());
         }
     }
 }