Esempio n. 1
0
File: Acl.php Progetto: nabble/ajde
 private static function getUser()
 {
     if (!isset(self::$_user)) {
         self::$_user = Ajde_User::getLoggedIn();
     }
     return self::$_user;
 }
Esempio n. 2
0
 public static function __bootstrap()
 {
     if (Ajde_User::getLoggedIn()) {
         return true;
     }
     $user = new UserModel();
     $user->verifyCookie(false);
     return true;
 }
Esempio n. 3
0
 public static function __bootstrap()
 {
     Ajde_Model::register('user');
     if (Ajde_User::getLoggedIn()) {
         return true;
     }
     $user = new UserModel();
     $user->verifyCookie();
     return true;
 }
Esempio n. 4
0
 public static function __bootstrap()
 {
     if (($user = Ajde_User::getLoggedIn()) && $user->getDebug()) {
         Config::set('app.debug', true);
         $htmlProcessors = config('layout.filters.documentProcessors.html');
         if (is_array($htmlProcessors) && !in_array('Debugger', $htmlProcessors)) {
             $htmlProcessors[] = 'Debugger';
             Config::set('layout.filters.documentProcessors.html', $htmlProcessors);
         }
     }
     return true;
 }
Esempio n. 5
0
 public static function mergeUserToClient()
 {
     if ($user = Ajde_User::getLoggedIn()) {
         // Do we have a saved cart for logged in user?
         $userCart = new CartModel();
         if ($userCart->loadByUser($user)) {
             // Do we have a saved cart for client?
             $clientCart = new CartModel();
             if ($clientCart->loadByClient() === false) {
                 $clientCart->client = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
                 $clientCart->insert();
             }
             foreach ($userCart->getItems() as $item) {
                 /* @var $item Ajde_Shop_Cart_Item */
                 $clientCart->addItem($item->getEntity(), null, $item->getQty());
             }
             $userCart->delete();
         }
     }
 }
Esempio n. 6
0
 private function submission($crudId, $id)
 {
     $session = new Ajde_Session('AC.Crud');
     /* @var $crud Ajde_Crud */
     $crud = $session->getModel($crudId);
     // verify that we have a valid crud model
     if (!$crud) {
         return ['success' => false];
     }
     /* @var $model FormModel */
     $model = $crud->getModel();
     $model->setOptions($crud->getOptions('model'));
     // Get POST params
     $post = Ajde_Http_Request::globalPost();
     $id = issetor($post['id']);
     // verify that we have a valid form model
     if (!$id) {
         return ['success' => false];
     }
     // load form
     $model->loadByPK($id);
     $model->populate($post);
     // validate form
     Ajde_Event::trigger($model, 'beforeCrudSave', [$crud]);
     if (!$model->validate($crud->getOptions('fields'))) {
         return ['operation' => 'save', 'success' => false, 'errors' => $model->getValidationErrors()];
     }
     // prepare submission
     $values = [];
     foreach ($post as $key => $value) {
         if (substr($key, 0, 5) === 'meta_') {
             $metaId = str_replace('meta_', '', $key);
             $metaName = MetaModel::getNameFromId($metaId);
             $values[$metaName] = $value;
         }
     }
     $entryText = '';
     foreach ($values as $k => $v) {
         $entryText .= $k . ': ' . $v . PHP_EOL;
     }
     $submission = new SubmissionModel();
     $submission->form = $id;
     $submission->ip = $_SERVER['REMOTE_ADDR'];
     $submission->user = Ajde_User::getLoggedIn();
     $submission->entry = json_encode($values);
     $submission->entry_text = $entryText;
     $success = $submission->insert();
     if ($success === true) {
         // Destroy reference to crud instance
         $session->destroy($crudId);
         // set message for next page
         Ajde_Session_Flash::alert(trans('Form submitted successfully'));
         $mailer = new Ajde_Mailer();
         // send email to administrator
         $body = 'Form: ' . $model->displayField() . '<br/><br/>' . nl2br($entryText);
         $mailer->SendQuickMail(config('app.email'), config('app.email'), config('app.title'), 'New form submission', $body);
         // send email to user
         $email = $model->getEmail();
         /* @var $email EmailModel */
         $email_to = $model->getEmailTo();
         /* @var $email MetaModel */
         $email_address = issetor($post['meta_' . $email_to->getPK()]);
         if ($email->hasLoaded() && $email_to->hasLoaded() && $email_address) {
             $mailer->sendUsingModel($email->getIdentifier(), $email_address, $email_address, ['entry' => nl2br($entryText)]);
         }
     }
     return ['operation' => 'save', 'id' => $model->getPK(), 'displayField' => $model->get($model->getDisplayField()), 'success' => $success];
 }
Esempio n. 7
0
File: User.php Progetto: nabble/ajde
 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;
 }
Esempio n. 8
0
 public function __wakeup()
 {
     parent::__wakeup();
     $this->registerEvents();
 }