示例#1
0
 public function useSession()
 {
     if (!$this->_useSession) {
         $config = Modules::load_multiple('rights', 'memberspace', 'config/', 'config');
         $this->_useSession = $config['rights_use_session'] !== FALSE;
     }
     return $this->_useSession;
 }
 public function __construct($basemodel = 'memberspace/post')
 {
     $CI =& get_instance();
     $this->_ci = $CI;
     $this->_ci->load->library('form_validation');
     $this->_ci_form_validation = $this->_ci->form_validation;
     $this->_ci->load->library('upload');
     $this->_ci_upload = $CI->upload;
     $this->_ci->load->library('flashmessages/flashMessagesManager');
     $this->_validation_rules = Modules::load_multiple('form_validation', 'memberspace', 'config/', 'config');
     $this->_upload_paths = Modules::load_multiple('upload_paths', 'memberspace', 'config/', 'config');
     $this->setCurrentPostModel($basemodel);
 }
示例#3
0
 protected function doSave($id = null, $model = 'blog/blogpost', $redirect = false)
 {
     $this->load->helper('memberspace/authorization');
     $this->load->helper('memberspace/connection');
     $post = $this->input->post();
     $this->load->library('memberspace/postManager', $model);
     $rules = Modules::load_multiple('form_validation', 'blog', 'config/', 'config');
     if (isset($rules[$model])) {
         $this->postmanager->registerModelRules($model, $rules[$model]);
     }
     $upload_path = Modules::load_multiple('upload_paths', 'blog', 'config/', 'config');
     if (isset($upload_path[$model])) {
         $this->postmanager->registerModelUploadPath($model, $upload_path[$model]);
     }
     $this->postmanager->setCurrentPostModel($model);
     if ($id) {
         $pop = $this->postmanager->getAPostModelAsArray($id);
     } else {
         $pop = array();
     }
     if (!isset($post['save-' . $this->postmanager->getPostModelName()])) {
         return $pop;
     }
     $pop = $post;
     if (!$post) {
         return $pop;
     }
     $is_update = isset($post['id']);
     if ($is_update && !user_can('update', $model, $post['id'])) {
         $this->addError(translate('Vous ne pouvez pas modifier ce post.'));
         return $pop;
     } else {
         if (!user_can('add', $model)) {
             $this->addError(translate('Vous ne pouvez pas ajouter de post.'));
             return $pop;
         }
     }
     if (!$this->postmanager->validateDatas()) {
         $this->addError($this->postmanager->getLastValidationErrors());
         return $pop;
     }
     $datas = $this->input->post();
     $datas['user_id'] = user_id();
     $new_id = $this->postmanager->saveDatas($datas);
     $this->user->allowTo('*', $model, $new_id);
     $this->addSuccess(translate('Le post a bien été ' . ($is_update ? 'mis à jour' : 'ajouté')));
     if ($redirect) {
         redirect($redirect);
     }
     return $datas;
 }
 public function connectUserFromPost($post = null)
 {
     $this->_ci->load->library('form_validation');
     if ($post) {
         $this->_ci->form_validation->set_data($post);
     }
     $rules = Modules::load_multiple('form_validation', 'memberspace', 'config/', 'config');
     if (!isset($rules['login'])) {
         return;
     }
     $validation_rules = $rules['login'];
     $this->_ci->form_validation->set_rules($validation_rules);
     if (!$this->_ci->form_validation->run()) {
         add_error($this->_ci->form_validation->error_string());
         return;
     }
     if (!$post) {
         unset($_POST['login-user']);
         $post = $_POST;
     }
     $this->_ci->load->model('user');
     $user = $this->_user->checkUser($post['login'], $post['password']);
     if (!$user) {
         add_error(translate('Le nom d\'utilisateur entré est invalide (email ou pseudo).'));
         return;
     }
     $this->_user->connect($user->id);
     add_success(translate('Vous vous êtes connecté avec succès !'));
     if (isset($post['rememberme']) && $post['rememberme']) {
         $cookie = $this->getCookie();
         $cookie['value'] = $user->id;
         set_cookie($cookie);
     }
     if ($this->_ci->session->userdata('login_redirect_url')) {
         redirect($this->_ci->session->userdata('login_redirect_url'));
     } else {
         redirect(current_url());
     }
 }
示例#5
0
 public function save($mailRedirect = 'memberspace/confirmation/confirm', $redirect = null)
 {
     $rules = Modules::load_multiple('form_validation', 'memberspace', 'config/', 'config');
     $post = $this->input->post();
     if (!$post) {
         return array();
     }
     $this->load->library('form_validation');
     if (!isset($rules['myuser'])) {
         return $post;
     }
     $this->form_validation->set_rules($rules['myuser']);
     if (!$this->form_validation->run()) {
         add_error($this->form_validation->error_string());
         return $post;
     }
     unset($_POST['save-user']);
     $this->load->model('myuser');
     $post = $this->input->post();
     if (isset($post['id']) && !user_can('update', 'user', $post['id'])) {
         return $post;
     }
     // It's important to make a call to $this->input->post() again
     $userId = $this->myuser->save($post);
     if (!isset($post['id'])) {
         $this->sendMailConfirmation($userId, $mailRedirect);
         $this->load->model('memberspace/right');
         $this->right->allowUserTo($userId, '*', 'user', $userId);
         $this->user->addToGroup('users', $userId);
         add_success('Vous avez bien été inscrit !');
     } else {
         add_success('Vous avez bien mis à jour vos informations');
     }
     if ($redirect) {
         redirect($redirect);
     }
     return $post;
 }