/** * * @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 getAuthenticationURL($returnto = '') { $connection = $this->getProvider(); // set returnto in session, google is very strict with callback urls $returntoSession = new Ajde_Session('returnto'); $returntoSession->set('url', $returnto); return $connection->createAuthUrl(); }
public static function get($key) { $session = new Ajde_Session('AC.Flash'); if ($session->has($key)) { return $session->getOnce($key); } else { return false; } }
public static function get($key) { $session = new Ajde_Session('AC.Flash'); if ($session->has($key)) { // Disable the cache, as getting a flashed string means outputting some message to the user Ajde_Cache::getInstance()->disable(); return $session->getOnce($key); } else { return false; } }
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; }
private function purgeRevisions($crudId) { $session = new Ajde_Session('AC.Crud'); /* @var $crud Ajde_Crud */ $crud = $session->getModel($crudId); /* @var $model Ajde_Model */ $model = $crud->getModel(); $success = $model->purgeRevisions(); return ['operation' => 'purgeRevisions', 'success' => $success, 'message' => 'Revisions purged']; }
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 startNew() { $session = new Ajde_Session('AC.Shop'); $session->destroy(); return $this->redirect('shop/cart'); }
public function save($crudId, $id) { $session = new Ajde_Session('AC.Crud'); /* @var $crud Ajde_Crud */ $crud = $session->getModel($crudId); /* @var $model Ajde_Model */ $model = $crud->getModel(); $model->setOptions($crud->getOptions('model')); // Get POST params $post = $_POST; foreach ($post as $key => $value) { // Include empty values, so we can set them to null if the table structure allows us // if (empty($value)) { // unset($post[$key]); // } } $id = issetor($post["id"]); $operation = empty($id) ? 'insert' : 'save'; if ($operation === 'save') { $model->loadByPK($id); } $model->populate($post); if (!$model->validate($crud->getOptions('fields'))) { return array('operation' => $operation, 'success' => false, 'errors' => $model->getValidationErrors()); } $success = $model->{$operation}(); if ($success === true) { // Destroy reference to crud instance $session->destroy($crudId); // Set flash alert Ajde_Session_Flash::alert('Record ' . ($operation == 'insert' ? 'added' : 'saved')); } return array('operation' => $operation, 'id' => $model->getPK(), 'success' => $success); }
public function logout() { // First destroy current session session_regenerate_id(); $session = new Ajde_Session('user'); $session->destroy(); $cookie = new Ajde_Cookie(Config::get('ident') . '_user'); $cookie->destroy(); }
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 logout() { // First destroy current session // TODO: overhead to call session_regenerate_id? is it not required?? //session_regenerate_id(); $session = new Ajde_Session('user'); $session->destroy(); $cookie = new Ajde_Cookie(config('app.id') . '_user'); $cookie->destroy(); self::$_user = null; }
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; }