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();
 }
Example #2
0
 public static function get($key)
 {
     $session = new Ajde_Session('AC.Flash');
     if ($session->has($key)) {
         return $session->getOnce($key);
     } else {
         return false;
     }
 }
Example #3
0
 /**
  *
  * @return UserModel 
  */
 public static function getLoggedIn()
 {
     $session = new Ajde_Session('user');
     if ($session->has('model')) {
         $user = $session->getModel('model');
         return $user;
     } else {
         return false;
     }
 }
Example #4
0
 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;
     }
 }
Example #5
0
File: User.php Project: nabble/ajde
 /**
  * @return UserModel
  */
 public static function getLoggedIn()
 {
     if (!isset(self::$_user)) {
         $session = new Ajde_Session('user');
         if ($session->has('model')) {
             $user = $session->getModel('model');
             self::$_user = $user;
         } else {
             self::$_user = false;
         }
     }
     return self::$_user;
 }
 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();
 }
Example #7
0
 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);
         }
     }
 }
Example #8
0
 private static function _getTokenDictionary(&$session = null)
 {
     if (!isset($session)) {
         $session = new Ajde_Session('AC.Form');
     }
     $tokenDictionary = $session->has('formTokens') ? $session->get('formTokens') : [];
     if (!is_array($tokenDictionary)) {
         $tokenDictionary = [];
     }
     return $tokenDictionary;
 }
Example #9
0
File: Crud.php Project: nabble/ajde
 /**
  * @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();
 }
Example #10
0
 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();
 }
Example #11
0
 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');
 }
Example #13
0
 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;
 }