Пример #1
0
 public static function mergeClientToUser()
 {
     if ($user = Ajde_User::getLoggedIn()) {
         // Do we have a saved client cart?
         $clientCart = new CartModel();
         if ($clientCart->loadByClient()) {
             // Do we have a saved cart for logged in user?
             $userCart = new CartModel();
             if ($userCart->loadByUser($user) === false) {
                 $userCart->user = $user->getPK();
                 $userCart->insert();
             }
             if ($userCart->hasItems()) {
                 // Set alert message
                 Ajde_Session_Flash::alert(trans('Your items are still in the shopping cart'));
             }
             // Merge items
             foreach ($clientCart->getItems() as $item) {
                 /* @var $item Ajde_Shop_Cart_Item */
                 $userCart->addItem($item->getEntity(), null, $item->getQty());
             }
             // And delete client
             $clientCart->delete();
         }
     }
 }
Пример #2
0
 public static function mergeClientToUser()
 {
     Ajde_Model::register('user');
     Ajde_Model::register('shop');
     if ($user = Ajde_User::getLoggedIn()) {
         // Do we have a saved client cart?
         $clientCart = new CartModel();
         if ($clientCart->loadByClient()) {
             // Do we have a saved cart for logged in user?
             $userCart = new CartModel();
             if ($userCart->loadByUser($user) === false) {
                 $userCart->user = $user->getPK();
                 $userCart->insert();
             }
             if ($userCart->hasItems()) {
                 // Set alert message
                 Ajde_Session_Flash::alert(__('We updated your shopping cart now you\'re logged in'));
             }
             // Merge items
             foreach ($clientCart->getItems() as $item) {
                 /* @var $item Ajde_Shop_Cart_Item */
                 $userCart->addItem($item->getEntity(), null, $item->getQty());
             }
             // And delete client
             $clientCart->delete();
         }
     }
 }
Пример #3
0
 public function loginJson()
 {
     $user = new UserModel();
     $id = Ajde::app()->getRequest()->getPostParam('id');
     $return = [false];
     if (false !== $user->loadByPK($id)) {
         $user->login();
         Ajde_Session_Flash::alert(sprintf(trans('Welcome back %s'), $user->getFullname()));
         $return = ['success' => true];
     } else {
         $return = ['success' => false];
     }
     return $return;
 }
Пример #4
0
 public function disconnect()
 {
     $returnto = Ajde::app()->getRequest()->getParam('returnto', '');
     if ($user = $this->getLoggedInUser()) {
         // should always be true, since we are inside a Ajde_User_Controller
         $sso = new SsoModel();
         if ($sso->loadByFields(['user' => $user->getPK(), 'provider' => $this->_providername])) {
             $this->_provider->destroySession();
             $sso->delete();
             Ajde_Session_Flash::alert('Disconnected from ' . ucfirst($this->_providername));
             $this->redirect($returnto);
         } else {
             Ajde_Session_Flash::alert('Could not disconnect from ' . ucfirst($this->_providername));
             $this->redirect($returnto);
         }
     }
 }
Пример #5
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];
 }
Пример #6
0
 public function registerJson()
 {
     $user = new UserModel();
     $returnto = Ajde::app()->getRequest()->getPostParam('returnto', false);
     $username = Ajde::app()->getRequest()->getPostParam($user->usernameField);
     $password = Ajde::app()->getRequest()->getPostParam('password');
     $passwordCheck = Ajde::app()->getRequest()->getPostParam('passwordCheck');
     $email = Ajde::app()->getRequest()->getPostParam('email', false);
     $fullname = Ajde::app()->getRequest()->getPostParam('fullname', false);
     $return = array(false);
     $shadowUser = new UserModel();
     if (empty($username) || empty($password)) {
         $return = array('success' => false, 'message' => __("Please provide " . $user->usernameField . " and password"));
     } else {
         if ($shadowUser->loadByField($shadowUser->usernameField, $username)) {
             $return = array('success' => false, 'message' => __(ucfirst($user->usernameField) . " already exist"));
         } else {
             if ($password !== $passwordCheck) {
                 $return = array('success' => false, 'message' => __("Passwords do not match"));
             } else {
                 if (empty($email)) {
                     $return = array('success' => false, 'message' => __("Please provide an e-mail address"));
                 } else {
                     if (Ajde_Component_String::validEmail($email) === false) {
                         $return = array('success' => false, 'message' => __('Please provide a valid e-mail address'));
                     } else {
                         if ($shadowUser->loadByField('email', $email)) {
                             $return = array('success' => false, 'message' => __("A user with this e-mail address already exist"));
                         } else {
                             if (empty($fullname)) {
                                 $return = array('success' => false, 'message' => __("Please provide a full name"));
                             } else {
                                 $user->set('email', $email);
                                 $user->set('fullname', $fullname);
                                 if ($user->add($username, $password)) {
                                     $user->login();
                                     Ajde_Session_Flash::alert(sprintf(__('Welcome %s, you are now logged in.'), $fullname));
                                     $return = array('success' => true, 'returnto' => $returnto);
                                 } else {
                                     $return = array('success' => false, 'message' => __("Something went wrong"));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $return;
 }
Пример #7
0
 public function cancel()
 {
     // Edit existing transaction?
     $transaction = new TransactionModel();
     $session = new Ajde_Session('AC.Shop');
     if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) {
         $transaction->payment_status = 'cancelled';
         $transaction->save();
         $session->destroy();
     }
     Ajde_Session_Flash::alert(trans('Your order has been cancelled', 'shop'));
     $this->redirect('shop');
 }
Пример #8
0
 public function modelJson()
 {
     $usergroup = Ajde::app()->getRequest()->getPostParam('usergroup', []);
     $model = Ajde::app()->getRequest()->getPostParam('model');
     $preset = Ajde::app()->getRequest()->getPostParam('preset');
     $options = $this->_modelPermissions[$model][$preset];
     foreach ($usergroup as $ugId => $acl) {
         AclModel::removeModelPermissions($ugId, $options['model'], $options['extra']);
         foreach ($acl as $permission => $actions) {
             foreach (explode('|', $actions) as $action) {
                 if ($action) {
                     AclModel::addPermission($permission, 'model', $ugId, $options['model'], $action, $options['extra']);
                 }
             }
         }
     }
     Ajde_Session_Flash::alert('Access updated for ' . $model . ': ' . $preset);
     return ['success' => true];
 }
 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);
 }
Пример #10
0
 public function verifyCookie()
 {
     $cookie = new Ajde_Cookie(Config::get('ident') . '_user');
     if (!$cookie->has('auth')) {
         return false;
     }
     $auth = $cookie->get('auth');
     list($uid, $hash) = explode(':', $auth);
     if (!$this->loadByPK($uid)) {
         return false;
     }
     if ($this->getCookieHash() === $hash) {
         $this->login();
         Ajde_Session_Flash::alert(sprintf(__('Welcome back %s, we automatically logged you in.'), $this->getFullname()));
     } else {
         return false;
     }
 }
Пример #11
0
 public function verifyCookie($includeDomain = true)
 {
     $cookie = new Ajde_Cookie(config('app.id') . '_user', true);
     if (!$cookie->has('auth')) {
         return false;
     }
     $auth = $cookie->get('auth');
     list($uid, $hash) = explode(':', $auth);
     if (!$this->loadByPK($uid)) {
         return false;
     }
     if ($this->getCookieHash($includeDomain) === $hash) {
         $this->login();
         Ajde_Session_Flash::alert(sprintf(trans('Welcome back %s'), $this->getFullname()));
         Ajde_Cache::getInstance()->disable();
     } else {
         return false;
     }
 }
Пример #12
0
 public function registerJson()
 {
     $user = new UserModel();
     $returnto = Ajde::app()->getRequest()->getPostParam('returnto', false);
     $username = Ajde::app()->getRequest()->getPostParam($user->usernameField);
     $password = Ajde::app()->getRequest()->getPostParam('password', '');
     $passwordCheck = Ajde::app()->getRequest()->getPostParam('passwordCheck', '');
     $providername = Ajde::app()->getRequest()->getPostParam('provider', false);
     $email = Ajde::app()->getRequest()->getPostParam('email', false);
     $fullname = Ajde::app()->getRequest()->getPostParam('fullname', false);
     $return = [false];
     $shadowUser = new UserModel();
     $provider = false;
     if ($providername) {
         $sso = config('user.sso.providers');
         if (!in_array($providername, $sso)) {
             Ajde_Http_Response::redirectNotFound();
         }
         $classname = 'Ajde_User_Sso_' . ucfirst($providername);
         /* @var $provider Ajde_User_SSO_Interface */
         $provider = new $classname();
     }
     if (empty($username)) {
         $return = ['success' => false, 'message' => trans('Please provide a ' . $user->usernameField . '')];
     } else {
         if (!$provider && empty($password)) {
             $return = ['success' => false, 'message' => trans('Please provide a password')];
         } else {
             if ($shadowUser->loadByField($shadowUser->usernameField, $username)) {
                 $return = ['success' => false, 'message' => trans(ucfirst($user->usernameField) . ' already exist')];
             } else {
                 if (!$provider && $password !== $passwordCheck) {
                     $return = ['success' => false, 'message' => trans('Passwords do not match')];
                 } else {
                     if (empty($email)) {
                         $return = ['success' => false, 'message' => trans('Please provide an e-mail address')];
                     } else {
                         if (Ajde_Component_String::validEmail($email) === false) {
                             $return = ['success' => false, 'message' => trans('Please provide a valid e-mail address')];
                         } else {
                             if ($shadowUser->loadByField('email', $email)) {
                                 $return = ['success' => false, 'message' => trans('A user with this e-mail address already exist')];
                             } else {
                                 if (empty($fullname)) {
                                     $return = ['success' => false, 'message' => trans('Please provide a full name')];
                                 } else {
                                     if ($provider && !$provider->getData()) {
                                         $return = ['success' => false, 'message' => trans('Something went wrong with fetching your credentials from an external service')];
                                     } else {
                                         $user->set('email', $email);
                                         $user->set('fullname', $fullname);
                                         if ($user->add($username, $password)) {
                                             if ($provider) {
                                                 $sso = new SsoModel();
                                                 $sso->populate(['user' => $user->getPK(), 'provider' => $providername, 'username' => $provider->getUsernameSuggestion(), 'avatar' => $provider->getAvatarSuggestion(), 'profile' => $provider->getProfileSuggestion(), 'uid' => $provider->getUidHash(), 'data' => serialize($provider->getData())]);
                                                 $sso->insert();
                                                 $user->copyAvatarFromSso($sso);
                                             }
                                             $user->login();
                                             $user->storeCookie($this->includeDomain);
                                             Ajde_Session_Flash::alert(sprintf(trans('Welcome %s, you are now logged in'), $fullname));
                                             $return = ['success' => true, 'returnto' => $returnto];
                                         } else {
                                             $return = ['success' => false, 'message' => trans('Something went wrong')];
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $return;
 }
Пример #13
0
 public function doCleanthumbs()
 {
     $toBeCleaned = Ajde_Fs_Find::findFilenames(UPLOAD_DIR . Ajde_Resource_Image::$_thumbDir . DIRECTORY_SEPARATOR, '*.*');
     foreach ($toBeCleaned as $file) {
         unlink(LOCAL_ROOT . UPLOAD_DIR . Ajde_Resource_Image::$_thumbDir . DIRECTORY_SEPARATOR . $file);
     }
     Ajde_Session_Flash::alert('Thumbnails will be refreshed next time they are loaded');
     return $this->redirect(Ajde_Http_Response::REDIRECT_REFFERER);
 }