/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { I18n::instance()->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { I18n::instance()->lang($this->cookies->get('lang')->getValue()); } // Send i18n, auth and langs to the view $this->view->setVars(array('auth' => Auth::instance(), 'i18n' => I18n::instance(), 'siteLangs' => array_map('__', $this->config->i18n->langs->toArray()))); }
/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { I18n::instance()->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { I18n::instance()->lang($this->cookies->get('lang')->getValue()); } $this->las = \Las\Library\Arr::from_model(Settings::find(array('status = ' . Settings::ACTIVE)), 'category', array('name' => 'value')); // Send i18n, auth and langs to the view $this->view->setVars(array('auth' => Auth::instance(), 'i18n' => I18n::instance(), 'siteLangs' => array_map('__', $this->config->i18n->langs->toArray()), 'las' => $this->las)); }
/** * Render views from volt files * * @package las * @version 1.0 */ public function voltAction() { $this->view->setVars(array('i18n' => I18n::instance(), 'auth' => Auth::instance())); ob_start(); $e = ''; foreach (array('frontend', 'backend', 'cli', 'documentation') as $module) { foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_PATH . '/app/' . $module . '/views/', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) { if (!$item->isDir() && $item->getExtension() == 'volt') { $this->view->setViewsDir(ROOT_PATH . '/app/' . $module . '/views/'); $subPath = $iterator->getSubPathName(); $file = strstr($item->getFilename(), '.volt', true); $dir = strstr($subPath, $item->getFilename(), true); $e .= $this->view->partial($dir . $file); } } } ob_get_clean(); //\Las\Console::log($e); }
/** * New payment Action * * @package las * @version 1.0 */ public function newAction() { $params = $this->router->getParams(); if (Auth::instance()->logged_in() && isset($params[0]) && ($adapter = $params[0])) { if ($checkout = $this->session->get('checkout')) { switch ($adapter) { case 'dotpay': $this->view->setVar('adapter', $this->tag->linkTo(array('http://www.dotpay.pl', $this->tag->image(array('img/dotpay.png', 'alt' => 'dotpay')), 'target' => '_blank', 'local' => false))); break; default: $this->view->setVar('adapter', $this->tag->linkTo(array('http://www.paypal.com', $this->tag->image(array('img/paypal.png', 'alt' => 'dotpay')), 'target' => '_blank', 'local' => false))); break; } if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $payment = new Payments(); $payment = $payment->add($checkout); // Check if new payment was valid and added if ($payment instanceof \Las\Models\Payments) { // Switch to payment adapter switch ($adapter) { case 'dotpay': $dotpay = Payment::instance('dotpay'); $fields = array('currency' => 'USD', 'amount' => number_format($payment->total, 2, '.', ''), 'lang' => substr(I18n::instance()->lang(), 0, 2), 'description' => __('Chocolate') . ' ' . $this->config->app->name, 'control' => $payment->control, 'type' => 3, 'buttontext' => __('Back to site'), 'email' => $payment->email, 'firstname' => $payment->firstname, 'lastname' => $payment->lastname); $this->view->pick('msg'); $this->tag->setTitle(__('Redirect')); $this->view->setVar('title', __('Redirect')); $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Notice') . '!</strong> ' . __("Redirecting to dotpay")); $this->view->setVar('content', $dotpay->process($fields)); break; default: $paypal = Payment::instance('paypal'); $fields = array('AMT' => $payment->total, 'CURRENCYCODE' => 'USD', 'LOCALECODE' => substr(I18n::instance()->lang(), 0, 2), 'NOSHIPPING' => '1', 'HDRIMG' => $this->url->getStatic('img/logo.png'), 'EMAIL' => $this->config->app->admin, 'ALLOWNOTE' => '0', 'PAYMENTREQUEST_0_AMT' => $payment->total, 'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', 'PAYMENTREQUEST_0_DESC' => $this->config->app->name, 'L_PAYMENTREQUEST_0_NAME0' => __('Chocolate') . ' ' . $this->config->app->name, 'L_PAYMENTREQUEST_0_AMT0' => $payment->amount, 'L_PAYMENTREQUEST_0_QTY0' => $payment->quantity); $paypal->process($fields); // Check that the response from the Paypal server is ok. if ($paypal->get('ACK') === 'Success') { // Store token in SESSION $this->session->set('paypal_token_' . $paypal->get('TOKEN'), $fields['AMT']); // We now send the user to the Paypal site for them to provide their details $fields['token'] = $paypal->get('TOKEN'); unset($fields['PAYMENTACTION']); $payment->control = $fields['token']; $payment->date_update = date('Y-m-d H:i:s'); $payment->response = json_encode($paypal->get()); $payment->save(); $url = $paypal->redirectURL('express-checkout', $fields); $this->response->redirect($url, true); } break; } } else { $this->view->setVar('errors', $payment); $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } } } else { $this->response->redirect('order'); } } else { $this->response->redirect('user/signin'); } }
/** * Log out Action * * @package las * @version 1.0 */ public function signoutAction() { Auth::instance()->logout(); $this->response->redirect(NULL); }
/** * Set the auth service * * @package las * @version 1.0 * * @return void */ protected function auth() { $this->_di->setShared('auth', function () { return Auth::instance(); }); }
/** * Sign up User method * * @version 1.0 */ public function signup($role = 'login') { $validation = new \Las\Extension\Validation(); $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('username', new \Las\Extension\Uniqueness(array('model' => '\\Las\\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 \Las\Extension\Uniqueness(array('model' => '\\Las\\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->getDI()->getShared('request')->getPost('username'); $this->password = Auth::instance()->hash($this->getDI()->getShared('request')->getPost('password')); $this->email = $this->getDI()->getShared('request')->getPost('email'); $this->logins = 0; if ($this->create() === true) { if ($role == 'admin') { return $this; } else { $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key); $email = new Email(); $email->prepare(__('Activation'), $this->getDI()->getShared('request')->getPost('email'), 'activation', array('username' => $this->getDI()->getShared('request')->getPost('username'), 'hash' => $hash)); if ($email->Send() === true) { unset($_POST); return true; } else { \Las\Bootstrap::log($email->ErrorInfo); return false; } } } else { \Las\Bootstrap::log($this->getMessages()); return $this->getMessages(); } } }