Ejemplo n.º 1
0
 public function insert($data = array(), $auth = NULL)
 {
     if (!$this->_function_check(false, $data)) {
         return false;
     }
     if (!isset($data['title']) || empty($data['title'])) {
         $this->error = 'No Title present.';
         return false;
     }
     if (!isset($data['body']) || empty($data['body'])) {
         $this->error = 'No Body given.';
         return false;
     }
     $data['date'] = strtotime($data['date']);
     $data['attachment'] = isset($data['attachment']) && !empty($data['attachment']) ? $data['attachment'] : '';
     $data['image_align'] = isset($data['image_align']) && !empty($data['image_align']) ? $data['image_align'] : '';
     $data['image_caption'] = isset($data['image_caption']) && !empty($data['image_caption']) ? $data['image_caption'] : '';
     $data['date_published'] = isset($data['date_published']) && !empty($data['date_published']) ? strtotime($data['date_published']) : $data['date'];
     $data['author'] = $data['created_by'] = $data['modified_by'] = isset($data['author']) && !empty($data['author']) ? $data['author'] : ($auth != NULL ? $auth->user_id() : 1);
     // What's the default category?
     $data['category_id'] = !isset($data['category_id']) ? 1 : $data['category_id'];
     // What's the default status?
     $data['status_id'] = !isset($data['status_id']) ? 1 : $data['status_id'];
     $id = parent::insert($data);
     Events::trigger('after_create_news', $id);
     return $id;
 }
Ejemplo n.º 2
0
 public function log_activity($user_id = null, $activity = '', $module = 'any')
 {
     if (!is_numeric($user_id) || empty($activity)) {
         logit('Not enough information provided to insert activity.');
     }
     $data = array('user_id' => $user_id, 'activity' => $activity, 'module' => $module);
     return parent::insert($data);
 }
 public function set_for_role($role_id = null, $permissions = array())
 {
     if (empty($role_id) || !is_numeric($role_id)) {
         return false;
     }
     $role = $this->find_by('role_id', $role_id);
     if ($role) {
         // remove existing permissions
         $this->delete_for_role($role_id);
     }
     // set the permissions
     foreach ($permissions as $key => $permission_id) {
         $data = array('role_id' => $role_id, 'permission_id' => $permission_id);
         $id = parent::insert($data);
     }
 }
Ejemplo n.º 4
0
 public function insert($data = array())
 {
     if (!$this->_function_check(false, $data)) {
         return false;
     }
     if (!isset($data['password']) || empty($data['password'])) {
         $this->error = 'No Password present.';
         return false;
     }
     if (!isset($data['email']) || empty($data['email'])) {
         $this->error = 'No Email given.';
         return false;
     }
     // Is this a unique email?
     if ($this->is_unique('email', $data['email']) == false) {
         $this->error = 'Email already exists.';
         return false;
     }
     if (empty($data['username'])) {
         unset($data['username']);
     }
     list($password, $salt) = $this->hash_password($data['password']);
     unset($data['password'], $data['pass_confirm'], $data['submit']);
     $data['password_hash'] = $password;
     $data['salt'] = $salt;
     $data['zipcode'] = !empty($data['zipcode']) ? $data['zipcode'] : null;
     // Handle the country
     if (isset($data['iso'])) {
         $data['country_iso'] = $data['iso'];
         unset($data['iso']);
     }
     // What's the default role?
     if (!isset($data['role_id'])) {
         // We better have a guardian here
         if (!class_exists('Role_model')) {
             $this->load->model('roles/Role_model', 'role_model');
         }
         $data['role_id'] = $this->role_model->default_role_id();
     }
     $id = parent::insert($data);
     Events::trigger('after_create_user', $id);
     return $id;
 }
Ejemplo n.º 5
0
 /**
  * Create a new user in the database.
  *
  * @param array $data An array of user information. 'password' and either 'email'
  * or 'username' are required, depending on the 'auth.use_usernames' setting.
  * 'email' or 'username' must be unique. If 'role_id' is not included, the default
  * role from the Roles model will be assigned.
  *
  * @return boolean|integer The ID of the new user on success, else false.
  */
 public function insert($data = array())
 {
     $id = parent::insert($data);
     return $id;
 }
Ejemplo n.º 6
0
 /**
  * Logs a new activity.
  *
  * @access public
  *
  * @param int    $user_id  An int id of the user that performed the activity.
  * @param string $activity A string detailing the activity. Max length of 255 chars.
  * @param string $module   The name of the module that set the activity.
  *
  * @return bool An int with the ID of the new object, or FALSE on failure.
  */
 public function log_activity($user_id = null, $activity = '', $module = 'any')
 {
     if (empty($user_id) || !is_integer($user_id) || $user_id == 0) {
         Template::set_message('You must provide a numeric user id to log activity.', 'error');
         return FALSE;
     } else {
         if (empty($activity)) {
             Template::set_message('Not enough information provided to insert activity.', 'error');
             return FALSE;
         }
     }
     $data = array('user_id' => $user_id, 'activity' => $activity, 'module' => $module);
     return parent::insert($data);
 }
Ejemplo n.º 7
0
 /**
  * Creates a new user in the database.
  *
  * Required parameters sent in the $data array:
  * * password
  * * A unique email address
  *
  * If no _role_id_ is passed in the $data array, it will assign the default role from <Roles> model.
  *
  * @access public
  *
  * @param array $data An array of user information.
  *
  * @return bool|int The ID of the new user.
  */
 public function insert($data = array())
 {
     // Display Name
     if (empty($data['display_name'])) {
         if ($this->settings_lib->item('auth.use_usernames') == 1 && !empty($data['username'])) {
             $data['display_name'] = $data['username'];
         } else {
             $data['display_name'] = $data['email'];
         }
     }
     $password = $this->auth->hash_password($data['password']);
     if (empty($password) || empty($password['hash'])) {
         return false;
     }
     $data['password_hash'] = $password['hash'];
     $data['password_iterations'] = $password['iterations'];
     unset($data['password'], $password);
     // What's the default role?
     if (!isset($data['role_id'])) {
         // We better have a guardian here
         if (!class_exists('Role_model')) {
             $this->load->model('roles/Role_model', 'role_model');
         }
         $data['role_id'] = $this->role_model->default_role_id();
     }
     $id = parent::insert($data);
     Events::trigger('after_create_user', $id);
     return $id;
 }
Ejemplo n.º 8
0
 /**
  * Create a new user in the database.
  *
  * @param array $data An array of user information. 'password' and either 'email'
  * or 'username' are required, depending on the 'auth.use_usernames' setting.
  * 'email' or 'username' must be unique. If 'role_id' is not included, the default
  * role from the Roles model will be assigned.
  *
  * @return boolean|integer The ID of the new user on success, else false.
  */
 public function insert($data = array())
 {
     // If 'display_name' is not provided, set it to 'username' or 'email'.
     if (empty($data['display_name'])) {
         if ($this->settings_lib->item('auth.use_usernames') == 1 && !empty($data['username'])) {
             $data['display_name'] = $data['username'];
         } else {
             $data['display_name'] = $data['email'];
         }
     }
     // Hash the password.
     $password = $this->auth->hash_password($data['password']);
     if (empty($password) || empty($password['hash'])) {
         return false;
     }
     $data['password_hash'] = $password['hash'];
     unset($data['password'], $password);
     // Get the default role if the role_id was not provided.
     if (!isset($data['role_id'])) {
         if (!class_exists('role_model', false)) {
             $this->load->model('roles/role_model');
         }
         $data['role_id'] = $this->role_model->default_role_id();
     }
     $id = parent::insert($data);
     Events::trigger('after_create_user', $id);
     return $id;
 }
Ejemplo n.º 9
0
 /**
  * Creates a new user in the database.
  *
  * Required parameters sent in the $data array:
  * * password
  * * A unique email address
  *
  * If no _role_id_ is passed in the $data array, it will assign the default role from <Roles> model.
  *
  * @access public
  *
  * @param array $data An array of user information.
  *
  * @return bool|int The ID of the new user.
  */
 public function insert($data = array())
 {
     if (!$this->_function_check(FALSE, $data)) {
         return FALSE;
     }
     if (!isset($data['password']) || empty($data['password'])) {
         $this->error = lang('us_no_password');
         return FALSE;
     }
     if (!isset($data['email']) || empty($data['email'])) {
         $this->error = lang('us_no_email');
         return FALSE;
     }
     // Is this a unique email?
     if ($this->is_unique('email', $data['email']) == FALSE) {
         $this->error = lang('us_email_taken');
         return FALSE;
     }
     if (empty($data['username'])) {
         unset($data['username']);
     }
     // Display Name
     if (!isset($data['display_name']) || isset($data['display_name']) && empty($data['display_name'])) {
         if ($this->settings_lib->item('auth.use_usernames') == 1 && !empty($data['username'])) {
             $data['display_name'] = $data['username'];
         } else {
             $data['display_name'] = $data['email'];
         }
     }
     list($password, $salt) = $this->hash_password($data['password']);
     unset($data['password'], $data['pass_confirm'], $data['submit']);
     $data['password_hash'] = $password;
     $data['salt'] = $salt;
     // What's the default role?
     if (!isset($data['role_id'])) {
         // We better have a guardian here
         if (!class_exists('Role_model')) {
             $this->load->model('roles/Role_model', 'role_model');
         }
         $data['role_id'] = $this->role_model->default_role_id();
     }
     $id = parent::insert($data);
     Events::trigger('after_create_user', $id);
     return $id;
 }