/** * Method to create a User Record * * Create a new User * * @url POST create * @smart-auto-routing false * * @access public * @return mixed */ public function create($show_password = false, $auto_gen_pass = true, $data = null) { if ($auto_gen_pass) { $temp_password = generate_random_str(6, 'abcdefghijklmnopqrstuvwxyz1234567890'); } else { $temp_password = $this->password; } $hasher = new Phpass\PasswordHash(8, false); $hashed_pass = $hasher->HashPassword($temp_password); $db = DataConnection::readWrite(); $u = $db->user(); if ($data == null) { $data = array('file_id' => $this->file_id, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'username' => $this->username, 'email' => $this->email, 'access_level' => $this->access_level, 'status' => $this->status, 'language' => $this->preferred_language, 'dashboard' => serialize($this->dashboard)); } else { $data['dashboard'] = serialize($data['dashboard']); } if (!isset($data['status'])) { $data['status'] = 1; } if (!isset($data['language'])) { $data['language'] = 'en'; } $data['password'] = $hashed_pass; $data['access_level'] = '51'; unset($data['password2']); unset($data['fn']); //print_debug($data); $result = $u->insert($data); foreach ($data as $key => $value) { $this->{$key} = $value; } $this->id = $result['id']; if ($show_password) { $this->temp_password = $hashed_password; } return $this; }