Esempio n. 1
0
 /**
  * Add new payment method
  *
  * @package     base-app
  * @version     2.0
  *
  * @param array $checkout data
  * @return object payment or errors
  */
 public function add($checkout)
 {
     $validation = new \Baseapp\Extension\Validation();
     $validation->add('firstname', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('lastname', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('email', new \Phalcon\Validation\Validator\Email());
     $messages = $validation->validate($_POST);
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->user_id = $this->getDI()->getShared('auth')->get_user()->id;
         $this->firstname = $this->getDI()->getShared('request')->getPost('firstname', 'string');
         $this->lastname = $this->getDI()->getShared('request')->getPost('lastname', 'string');
         $this->email = $this->getDI()->getShared('request')->getPost('email');
         $this->quantity = $checkout['quantity'];
         $this->amount = $checkout['price'];
         $this->total = $checkout['price'] * $checkout['quantity'];
         $date = date("Y-m-d H:i:s");
         $this->control = md5($this->getDI()->getShared('request')->getPost('email') . $date);
         $this->state = 'REQUEST';
         $this->date = $date;
         $this->note = $this->getDI()->getShared('request')->getPost('note', 'string');
         $this->ip = $this->getDI()->getShared('request')->getClientAddress();
         $this->user_agent = $this->getDI()->getShared('request')->getUserAgent();
         if ($this->create() === true) {
             return $this;
         } else {
             \Baseapp\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
 /**
  * Contact Action
  *
  * @package     base-app
  * @version     2.0
  */
 public function contactAction()
 {
     $this->tag->setTitle(__('Contact'));
     if ($this->request->isPost() === true) {
         $validation = new \Baseapp\Extension\Validation();
         $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10)));
         $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('email', new \Phalcon\Validation\Validator\Email());
         $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email')));
         $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email')));
         $messages = $validation->validate($_POST);
         if (count($messages)) {
             $this->view->setVar('errors', $validation->getMessages());
             $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
         } else {
             $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Message was sent"));
             $email = new \Baseapp\Library\Email();
             $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')));
             $email->addReplyTo($this->request->getPost('email'));
             if ($email->Send() === true) {
                 unset($_POST);
             } else {
                 \Baseapp\Bootstrap::log($email->ErrorInfo);
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Contact Action
  */
 public function contactAction()
 {
     $this->tag->setTitle(__('Contact'));
     $this->assets->addJs('js/forms.js');
     if ($this->request->isPost() === true) {
         $validation = new \Baseapp\Extension\Validation();
         $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10)));
         $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('email', new \Phalcon\Validation\Validator\Email());
         $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email')));
         // Recaptcha validation
         if ($this->config->recaptcha->enabled == '1') {
             $validation->add('g-recaptcha-response', new \Baseapp\Extension\Recaptcha());
         }
         $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email')));
         $messages = $validation->validate($_POST);
         if (count($messages)) {
             $this->view->setVar('errors', $validation->getMessages());
             $this->flashSession->warning('<i class="close icon"></i><div class="header">' . __('Warning') . '!</div> ' . __("Please correct the errors."));
         } else {
             $this->flashSession->success('<i class="close icon"></i><div class="header">' . __('Success') . '!</div> ' . __("Message was sent"));
             $email = new \Baseapp\Library\Email();
             $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')));
             $email->addReplyTo($this->request->getPost('email'));
             if ($email->Send() === true) {
                 unset($_POST);
             } else {
                 \Baseapp\Bootstrap::log($email->ErrorInfo);
             }
         }
     }
 }
Esempio n. 4
0
    // Global translation function
    if (!function_exists('__')) {
        /**
         * Translate message
         *
         * @package     base-app
         * @version     2.0
         *
         * @param string $string string to translate
         * @param array $values replace substrings
         *
         * @return string translated string
         */
        function __($string, array $values = NULL)
        {
            return \Baseapp\Library\I18n::instance()->_($string, $values);
        }
    }
    if (!defined('ROOT_PATH')) {
        define('ROOT_PATH', dirname(__DIR__));
    }
    require_once ROOT_PATH . '/app/Bootstrap.php';
    $app = new \Baseapp\Bootstrap(new \Phalcon\DI\FactoryDefault());
    echo $app->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    \Baseapp\Bootstrap::exception($e);
} catch (\PDOException $e) {
    \Baseapp\Bootstrap::exception($e);
} catch (\Exception $e) {
    \Baseapp\Bootstrap::exception($e);
}
Esempio n. 5
0
 /**
  * Catch the exception and log it, display pretty view
  *
  * @param \Exception $e
  */
 public static function exception(\Exception $e)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n");
     if ($config->app->env == "development") {
         // Display debug output
         $debug = new \Phalcon\Debug();
         $debug->onUncaughtException($e);
     } else {
         // Display pretty view of the error
         $di = new \Phalcon\DI\FactoryDefault();
         $view = new \Phalcon\Mvc\View\Simple();
         $view->setDI($di);
         $view->setViewsDir(APP_PATH . '/app/frontend/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config));
         // Log errors to file and send email with errors to admin
         \Baseapp\Bootstrap::log($errors);
     }
 }
Esempio n. 6
0
 /**
  * Catch the exception and log it
  *
  * @package     base-app
  * @version     2.0
  *
  * @param \Exception $e
  */
 public static function exception(\Exception $e)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n");
     if ($config->app->env == "development") {
         // Display debug output
         print_r($e);
     } else {
         // Log errors to file and send email with errors to admin
         \Baseapp\Bootstrap::log($errors);
     }
 }
Esempio n. 7
0
 /**
  * Resend activation email
  *
  * @param $user
  * @param bool|FALSE $email_address
  * @return bool
  * @throws \Exception
  * @throws \phpmailerException
  */
 public function resend($user, $email_address = FALSE)
 {
     $re_user = self::findFirst(array('conditions' => "id = '{$user}'"));
     $isAlreadyUnconfirmed = $this::getUserRoles($user, 'unconfirmed');
     if (!$isAlreadyUnconfirmed) {
         $this::setUserRole($user, 'unconfirmed');
     }
     if ($email_address) {
         $send_to = $email_address;
         // if user changed email address update user email address in database
         $re_user->email = $email_address;
         if ($re_user->update() !== TRUE) {
             \Baseapp\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     } else {
         $send_to = $re_user->email;
     }
     $hash = md5($user . $send_to . $re_user->password . $this->getDI()->getShared('config')->auth->hash_key);
     $email = new Email();
     $email->prepare(__('Activation'), $send_to, 'activation', array('username' => $re_user->username, 'hash' => $hash));
     if ($email->Send() === TRUE) {
         return TRUE;
     }
 }
Esempio n. 8
0
 /**
  * @return string Either an XML document or a gzipped file
  */
 public function render()
 {
     // Default uncompressed
     $response = $this->_xml->saveXML();
     if ($this->gzip) {
         // Try and gzip the file before we send it off.
         try {
             $response = gzencode($response, $this->compression);
         } catch (ErrorException $e) {
             \Baseapp\Bootstrap::exception($e);
         }
     }
     return $response;
 }
Esempio n. 9
0
 /**
  * Sign up User method
  *
  * @version     2.0
  */
 public function signup()
 {
     $validation = new \Baseapp\Extension\Validation();
     $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('username', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users')));
     $validation->add('username', new \Phalcon\Validation\Validator\StringLength(array('min' => 4, 'max' => 24)));
     $validation->add('password', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('repeatPassword', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'password')));
     $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('email', new \Phalcon\Validation\Validator\Email());
     $validation->add('email', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users')));
     $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email')));
     $validation->setLabels(array('username' => __('Username'), 'password' => __('Password'), 'repeatPassword' => __('Repeat password'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email')));
     $messages = $validation->validate($_POST);
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->username = $this->request->getPost('username');
         $this->password = $this->getDI()->getShared('auth')->hash($this->request->getPost('password'));
         $this->email = $this->request->getPost('email');
         $this->logins = 0;
         if ($this->create() === true) {
             $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key);
             $email = new Email();
             $email->prepare(__('Activation'), $this->request->getPost('email'), 'activation', array('username' => $this->request->getPost('username'), 'hash' => $hash));
             if ($email->Send() === true) {
                 unset($_POST);
                 return $this;
             } else {
                 \Baseapp\Bootstrap::log($email->ErrorInfo);
                 return false;
             }
         } else {
             \Baseapp\Bootstrap::log($this->getMessages());
             return false;
         }
     }
 }