Пример #1
0
 public function store()
 {
     //Load Tables
     $row = new UserTable();
     $data = $this->app->input->post->getArray();
     //$this->app->triggerEvent('onBeforeCRMUserSave', array(&$data));
     //date generation
     $date = date('Y-m-d H:i:s');
     if (!array_key_exists('id', $data)) {
         $data['created'] = $date;
         $data['time_zone'] = ConfigHelper::getConfigValue('timezone');
         $data['time_format'] = ConfigHelper::getConfigValue('time_format');
         $data['block'] = 0;
         $data['registerDate'] = $date;
         $data['activation'] = 0;
         $data['params'] = "";
     }
     if (array_key_exists('password', $data) && $data['password'] != "") {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     } else {
         unset($data['password']);
     }
     //generate team data
     $model = new Teams();
     if (array_key_exists('id', $data) && $data['id'] > 0) {
         $teamId = $this->getTeamId($data['id']);
     }
     //assign user priviliges
     $data['modified'] = $date;
     $data['admin'] = array_key_exists('admin', $data) && $data['admin'] == '1' ? 1 : 0;
     $data['exports'] = array_key_exists('exports', $data) && $data['exports'] == 'on' ? 1 : 0;
     $data['can_delete'] = array_key_exists('can_delete', $data) && $data['can_delete'] == 'on' ? 1 : 0;
     //republish / register users
     if (array_key_exists('id', $data) && $data['id'] != "") {
         $query = $this->db->getQuery(true);
         $query->clear()->select("id")->from("#__users")->where("id=" . $data['id']);
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         if ($id) {
             $data['id'] = $id;
             $data['published'] = 1;
         }
     }
     if (array_key_exists('team_id', $data) && $data['team_id'] == "") {
         unset($data['team_id']);
     }
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (array_key_exists('role_type', $data) && $data['role_type'] == "manager") {
         $teamModel = new Teams();
         $teamName = array_key_exists('team_name', $data) ? $data['team_name'] : "";
         $teamModel->createTeam($row->id, $teamName);
     }
     //if we are downgrading a users priviliges
     if (array_key_exists('manager_assignment', $data) && $data['manager_assignment'] != null && $data['manager_assignment'] != "") {
         $newTeamId = $this->getTeamId($data['manager_assignment']);
         $model->updateTeam($teamId, $newTeamId);
     }
     $row->id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $this->db->insertId();
     $this->updateUserMap($row);
     //$this->app->triggerEvent('onAfterCRMUserSave', array(&$data));
     return true;
 }
Пример #2
0
 public function createAdmin($admin)
 {
     $query = $this->db->getQuery(true);
     $userId = rand(0, 500);
     if (!ini_get('date.timezone')) {
         date_default_timezone_set('GMT');
     }
     // Create random salt/password for the admin user
     $cryptpass = \Cobalt\Helper\UsersHelper::hashPassword($admin['password']);
     $query = $this->db->getQuery(true);
     $columns = array($this->db->quoteName('id'), $this->db->quoteName('role_type'), $this->db->quoteName('admin'), $this->db->quoteName('name'), $this->db->quoteName('first_name'), $this->db->quoteName('last_name'), $this->db->quoteName('username'), $this->db->quoteName('email'), $this->db->quoteName('password'), $this->db->quoteName('block'), $this->db->quoteName('sendEmail'), $this->db->quoteName('registerDate'), $this->db->quoteName('lastvisitDate'), $this->db->quoteName('activation'), $this->db->quoteName('params'));
     $query->insert('#__users', true);
     $query->columns($columns);
     $query->values($this->db->quote($userId) . ', ' . $this->db->quote("exec") . ' , ' . $this->db->quote("1") . ', ' . $this->db->quote($admin['first_name'] . ' ' . $admin['last_name']) . ', ' . $this->db->quote($admin['first_name']) . ', ' . $this->db->quote($admin['last_name']) . ', ' . $this->db->quote($admin['username']) . ', ' . $this->db->quote($admin['email']) . ', ' . $this->db->quote($cryptpass) . ', ' . $this->db->quote('0') . ', ' . $this->db->quote('1') . ', ' . $this->db->quote(date("Y-m-d H:i:s")) . ', ' . $this->db->quote($this->db->getNullDate()) . ', ' . $this->db->quote('0') . ', ' . $this->db->quote(''));
     $this->db->setQuery($query);
     $this->db->execute();
     $columns = array($this->db->quoteName('user_id'), $this->db->quoteName('group_id'));
     $values = $this->db->quote($userId) . ', ' . $this->db->quote("2");
     $query->clear();
     $query->insert("#__user_usergroup_map")->columns($columns)->values($values);
     $this->db->setQuery($query);
     $this->db->execute();
     $this->admin = $admin;
     return true;
 }
Пример #3
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     if (!$data) {
         $data = $this->app->input->post->getArray();
     }
     //Load Table
     $row = new UserTable();
     if (isset($data['id']) && $data['id']) {
         $row->load($data['id']);
     }
     if (isset($data['fullscreen'])) {
         $data['fullscreen'] = !$row->fullscreen;
     }
     if (isset($data['password']) && $data['password']) {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     $data['modified'] = $date;
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //update users email address
     if (array_key_exists('email', $data)) {
         $this->updateEmail($row->id, $data['email']);
     }
     if (isset($data['team_name']) && $data['team_name']) {
         $teamModel = new Teams();
         $teamModel->createTeam($row->id, $data['team_name']);
     }
     $this->app->refreshUser();
     return $row->id;
 }