public function listHtml() { $cache = Ajde_Cache::getInstance(); $cache->disable(); if (Ajde::app()->getRequest()->has('edit') || Ajde::app()->getRequest()->has('new')) { return $this->editDefault(); } if (Ajde::app()->getRequest()->has('output') && Ajde::app()->getRequest()->get('output') == 'table') { Ajde::app()->getDocument()->setLayout(new Ajde_Layout('empty')); } $crud = $this->getCrudInstance(); /* @var $crud Ajde_Crud */ if (!$crud) { Ajde::app()->getResponse()->redirectNotFound(); } $session = new Ajde_Session('AC.Crud'); $session->setModel($crud->getHash(), $crud); $viewSession = new Ajde_Session('AC.Crud.View'); $sessionName = $crud->getSessionName(); if ($viewSession->has($sessionName)) { $crudView = $viewSession->get($sessionName); } else { $crudView = new Ajde_Collection_View($sessionName, $crud->getOption('list.view', array())); } $viewParams = Ajde::app()->getRequest()->getParam('view', array()); $crudView->setOptions($viewParams); $viewSession->set($sessionName, $crudView); $crud->getCollection()->setView($crudView); $view = $crud->getTemplate(); $view->assign('crud', $crud); return $view->render(); }
/** * * @param string $hash * @return Ajde_Resource */ public static function fromHash($hash) { // TODO: throw new Ajde_Core_Exception_Deprecated(); $session = new Ajde_Session('AC.Resource'); return $session->get($hash); }
public function checkout() { Ajde_Model::register($this); // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function callback() { // from querystring? $returnto = Ajde::app()->getRequest()->getParam('returnto', ''); if (empty($returnto)) { $returnto = Ajde_Http_Response::REDIRECT_HOMEPAGE; } // from session? $returntoSession = new Ajde_Session('returnto'); if ($returntoSession->has('url')) { $returnto = $returntoSession->get('url'); $returntoSession->destroy(); } if (!$this->_provider->isAuthenticated()) { Ajde_Session_Flash::alert('Permission request cancelled for ' . ucfirst($this->_providername)); $this->redirect($returnto); return false; } // We already have a user for this SSO, log that user in and redirect if ($user = $this->_provider->getUser()) { if ($this->getLoggedInUser()) { Ajde_Session_Flash::alert(ucfirst($this->_providername) . ' user ' . $this->_provider->getUsernameSuggestion() . ' is already connected to another account.'); $this->redirect($returnto); } else { $user->login(); $user->storeCookie(false); $this->redirect($returnto); } } else { // A user is already logged in, link this account and redirect if ($user = $this->getLoggedInUser()) { $sso = new SsoModel(); $sso->populate(['user' => $user->getPK(), 'provider' => $this->_providername, 'username' => $this->_provider->getUsernameSuggestion(), 'avatar' => $this->_provider->getAvatarSuggestion(), 'profile' => $this->_provider->getProfileSuggestion(), 'uid' => $this->_provider->getUidHash(), 'data' => serialize($this->_provider->getData())]); $sso->insert(); $user->copyAvatarFromSso($sso); $this->redirect($returnto); // No match found, redirect to register page } else { $username = $this->_provider->getUsernameSuggestion(); $email = $this->_provider->getEmailSuggestion(); $fullname = $this->_provider->getNameSuggestion(); $this->redirect('user/register?provider=' . $this->_providername . '&username='******'&email=' . esc($email) . '&fullname=' . esc($fullname) . '&hidepassword=1&returnto=' . $returnto); } } }
public function formUploadJson() { $optionsId = Ajde::app()->getRequest()->getParam('optionsId', array()); $session = new Ajde_Session('AC.Form'); $options = $session->get($optionsId); // Load UploadHelper.php $helper = new Ajde_Component_Form_UploadHelper(); $saveDir = $options['saveDir']; $allowedExtensions = $options['extensions']; // max file size in bytes $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $memory_limit = (int) ini_get('memory_limit'); $upload_mb = min($max_upload, $max_post, $memory_limit); $sizeLimit = $upload_mb * 1024 * 1024; $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $result = $uploader->handleUpload($saveDir); // Set content type to text/html for qqUploader bug 163 // @see https://github.com/valums/file-uploader/issues/163 Ajde::app()->getDocument()->setContentType('text/html'); // to pass data through iframe you will need to encode all html tags return $result; }
public static function verifyFormTime() { $session = new Ajde_Session('AC.Form'); $sessionTime = $session->get('formTime'); if (time() - $sessionTime < self::FORM_MIN_TIME || time() - $sessionTime > self::FORM_MAX_TIME) { return false; } else { return true; } }
/** * @param array $viewParams * @param bool|string $persist * * @return Ajde_Collection_View */ public function getCollectionView($viewParams = [], $persist = 'auto') { if (!$this->getCollection()->hasView()) { $viewSession = new Ajde_Session('AC.Crud.View'); $sessionName = $this->getSessionName(); if ($viewSession->has($sessionName)) { $crudView = $viewSession->get($sessionName); } else { $crudView = new Ajde_Collection_View($sessionName, $this->getOption('list.view', [])); $crudView->setColumns($this->getOption('list.show', $this->getFieldNames())); } // somehow, when altering crudView, the instance in the session gets updated as well, and we don't want that $crudView = clone $crudView; if (empty($viewParams)) { $viewParams = Ajde::app()->getRequest()->getParam('view', []); // if we have params, but no columns, assume a reset if (!empty($viewParams) && !isset($viewParams['columns'])) { $viewParams['columns'] = $this->getOption('list.show', $this->getFieldNames()); } } $crudView->setOptions($viewParams); if ($persist == 'auto' && $this->getOperation() == 'list' || $persist === true) { $viewSession->set($sessionName, $crudView); } $this->getCollection()->setView($crudView); } return $this->getCollection()->getView(); }
public function complete() { $cart = new CartModel(); $cart->loadCurrent(); $cart->emptyItems(); // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction')) { $transaction->loadByPK($session->get('currentTransaction')); } $session->destroy(); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function checkout() { // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); // Can we skip this step? if (!$transaction->hasLoaded() && !config('shop.offerLogin') && $cart->hasItems()) { $this->redirect('shop/transaction:setup'); } $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function paymentJson() { $request = Ajde::app()->getRequest(); $provider = $request->getPostParam('provider', false); if (empty($provider)) { return array('success' => false, 'message' => __('Please choose a payment provider')); } // Check for current transaction Ajde_Model::register($this); $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { if ($transaction->payment_status !== 'pending') { return array('success' => false, 'message' => __('Payment already initiated, please refresh this page')); } } else { return array('success' => false, 'message' => __('No current transaction found')); } $transaction->payment_provider = $provider; $provider = $transaction->getProvider(); $redirectUrl = $provider->getRedirectUrl(); if ($redirectUrl !== false) { $transaction->payment_status = 'requested'; $transaction->save(); $cart = new CartModel(); $cart->loadCurrent(); $cart->emptyItems(); if ($provider->usePostProxy()) { $this->setAction('postproxy'); $proxy = $this->getView(); $proxy->assign('provider', $provider); return array('success' => true, 'postproxy' => $proxy->render()); } return array('success' => true, 'redirect' => $redirectUrl); } return array('success' => false, 'message' => 'Could not contact the payment provider, please try again'); }
public function forgotJson() { $user = new UserModel(); $ident = Ajde::app()->getRequest()->getPostParam('user'); $found = false; $return = [false]; if (false !== $user->loadByField('email', $ident)) { $found = true; } if (false === $found && false !== $user->loadByField($user->usernameField, $ident)) { $found = true; } if (false !== $found) { if ($user->resetUser()) { Ajde_Session_Flash::alert(trans('A password reset link is sent to your e-mail address.')); $return = ['success' => true]; } else { $return = ['success' => false, 'message' => trans('We could not reset your password. Please contact our technical staff.')]; } } else { $session = new Ajde_Session('user'); $attempts = $session->has('attempts') ? $session->get('attempts') : 1; $session->set('attempts', $attempts + 1); if ($attempts % 4 === 0) { sleep(5); } $return = ['success' => false, 'message' => trans('No matching user found')]; } return $return; }