Ejemplo n.º 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());
         }
     }
 }
Ejemplo n.º 2
0
 public function verifyAction($code)
 {
     try {
         $pe = new \Sayvot\Misc\ParametersEncoder();
         $parameters = $pe->decodeLink("account/verify", $code);
         $account = Account::findFirstByIdAccount($parameters[0]);
         if (!$account) {
             throw new \InvalidArgumentException('No existe una cuenta con el id ingresado');
         }
         $user = User::findFirstByIdUser($parameters[1]);
         if (!$user) {
             throw new \InvalidArgumentException('No existe un usuario con el id ingresado');
         }
         if ($user->idAccount != $account->idAccount) {
             throw new \InvalidArgumentException('No existe un usuario con el id ingresado');
         }
         if ($account->accountplan->price + 0 != 0) {
             return $this->response->redirect("account/paymentdata/{$account->idAccount}");
         }
         $account->confirm = 1;
         if ($account->save()) {
             return $this->response->redirect("session/login");
         }
     } catch (InvalidArgumentException $ex) {
         $this->flashSession->error($ex->getMessage());
         return $this->response->redirect("error");
     } catch (Exception $ex) {
         $this->logger->log("Exception while verify account: {$ex->getMessage()}");
         $this->logger->log($ex->getTraceAsString());
         $this->flashSession->error($ex->getMessage());
         return $this->response->redirect("error");
     }
 }