/** * Register new user * @return json */ public function registerUser() { if ($this->input->server('REQUEST_METHOD') == 'POST') { // loads $this->load->model('admin/user_model'); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); // validate $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'required|matches[password_retype]'); $this->form_validation->set_rules('password_retype', 'Password', 'required'); $this->form_validation->set_rules('full_name', 'Full Name', 'required'); if ($this->form_validation->run() == FALSE) { return $this->output->set_content_type('application/json')->set_output(json_encode(array('status' => FALSE, 'error' => validation_errors()))); } else { // populate user $user = new User_model(); $user->email = $this->input->post('email'); $user->password = $this->input->post('password'); $user->full_name = $this->input->post('full_name'); $status = $user->insert(); return $this->output->set_content_type('application/json')->set_output(json_encode(array('status' => $status))); } } }
public function saveOrUpdate($data) { if (empty($data)) { throw new InvalidArgumentException('Data cannot be empty.'); } $user = new User_model(); $user->username = $data['username']; $user->password = $data['password']; $user->firstName = $data['firstName']; $user->lastName = $data['lastName']; $user->isAdmin = $data['isAdmin']; if (!empty($data['userId'])) { $user->userId = $data['userId']; $userId = $user->update(); return $userId; } $userId = $user->insert(); return $userId; }
/** * Register and log user in. * * @param string $email * @param string $password * @return boolean */ protected function register($email, $password) { $this->load->model('User_model'); $user = new User_model(); $user->email = $email; $user->password = $this->User_model->encrypt_password($password); $user->set_confirmation(); if ($user->insert()) { $this->set_currentuser($user); return $user; } else { return false; } }
/** * Register Edit / New User form data * (if 0 then is a new item) * @param integer $id item ID (if 0 then is a new item) * @param array $_post _POST array * @return void */ private function editing($id, $_post) { $msg = null; // check permission $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'users', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_user_creation', 0, 4); if (is_null($msg)) { // handle _post $post = array('lang' => $_post['lang'], 'id_group' => $_post['id_group'], 'username' => $_post['username'], 'description' => $_post['description'], 'mail' => $_post['mail'], 'phone' => $_post['phone'], 'level' => $_post['level']); // update password if (!empty($_post['password'])) { $post['password'] = X4Utils_helper::hashing($_post['password']); } // check if an user with the same username or password already exists $user = new User_model(); $check = (bool) $user->exists($post['username'], $post['mail'], $id); if ($check) { $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_USER_ALREADY_EXISTS', 'msg')); } else { $perm = new Permission_model(); if ($id) { // update $result = $user->update($id, $post); // update user privileges on areas $perm->set_aprivs($id, $_post['domain']); // redirect $where = '/detail/' . $id; } else { // insert $result = $user->insert($post); // redirect $where = ''; if ($result[1]) { $id = $result[0]; // set privileges on areas $perm->set_aprivs($id, $_post['domain']); // add privs on new user $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('users', $array, $_post['id_area']); // refactory permissions for the user $perm->refactory($id); } } // set message $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'users' . $where, 'title' => null); } } } $this->response($msg); }