Example #1
0
 function index_get()
 {
     $requested_data = $this->get("filter");
     $filters = $requested_data['filters'];
     $limit = $this->get('limit') ? $this->get('limit') : 50;
     $offset = $this->get('offset') ? $this->get('offset') : null;
     $users = new User(null, $this->entity);
     $users->limit($limit, $offset);
     if (isset($filters)) {
         foreach ($filters as $f) {
             $users->where($f['field'], $f['value']);
         }
     }
     $users->get_iterated();
     foreach ($users as $user) {
         $data[] = array('id' => intval($user->id), 'username' => $user->username, 'password' => $user->password, 'status' => boolval($user->status), 'created_at' => $user->created_at, 'updated_at' => $user->updated_at);
     }
     $users->flush_cache();
     if (isset($filters)) {
         foreach ($filters as $f) {
             $users->where($f['field'], $f['value']);
         }
     }
     $users->get_iterated();
     if ($users->result_count() > 0) {
         $this->response(array('results' => $data, 'count' => $users->result_count()), 200);
     } else {
         $this->response(array('results' => $data, 'count' => $users->result_count()), 200);
     }
 }
Example #2
0
 function index()
 {
     $users = new User();
     $users->include_related('group', 'name');
     $bug = $users->bug;
     $bug->select_func('COUNT', '*', 'count')->where_related_status('closed', FALSE)->where_related('user', 'id', '${parent}.id');
     $users->select_subquery($bug, 'bug_count');
     $users->get_iterated();
     $this->output->enable_profiler(TRUE);
     $this->load->view('template_header', array('title' => 'Users', 'section' => 'admin'));
     $this->load->view('users/index', array('users' => $users));
     $this->load->view('template_footer');
 }
Example #3
0
 function index()
 {
     list($params, $id) = $this->parse_params(func_get_args());
     // Create or update
     if ($this->method === 'get') {
         if (!$this->auth) {
             $this->error('401', 'Not authorized to perform this action.');
             return;
         }
     } else {
         // TODO: Stress test permissions
         $u = new User();
         switch ($this->method) {
             case 'post':
             case 'put':
                 if ($this->method == 'put') {
                     // Updates can only be carried out by the user or an administrator
                     if ($this->auth_user_id != $id && $this->auth_role != 'god' && $this->auth_role != 'admin') {
                         $this->error('401', 'Not authorized to perform this action.');
                         return;
                     }
                     $u->get_by_id($id);
                     if (!$u->exists()) {
                         $this->error('404', "User with ID: {$id} not found.");
                         return;
                     }
                 } else {
                     if (is_null($id)) {
                         // Only admins can create users
                         if ($this->auth_role != 'god' && $this->auth_role != 'admin') {
                             $this->error('401', 'Not authorized to perform this action.');
                             return;
                         }
                     }
                 }
                 $u->from_array($_POST, array(), true);
                 $this->redirect("/users/{$u->id}");
                 break;
                 // case 'delete':
                 // 	if ($this->auth_role != 'god' && $this->auth_role != 'admin')
                 // 	{
                 // 		$this->error('401', 'Not authorized to perform this action.');
                 return;
                 // 	}
                 // 	if (is_null($id))
                 // 	{
                 // 		$this->error('403', 'Required parameter "id" not present.');
                 return;
                 // 	}
                 // 	else
                 // 	{
                 // 		// TODO
                 // 	}
                 // 	exit;
                 break;
         }
     }
     $u = new User();
     // No id, so we want a list
     if (is_null($id)) {
         $options = array('page' => 1, 'limit' => false);
         $options = array_merge($options, $params);
         if (!is_numeric($options['limit'])) {
             $options['limit'] = false;
         }
         $final = $u->paginate($options);
         $data = $u->get_iterated();
         if (!$options['limit']) {
             $final['per_page'] = $data->result_count();
             $final['total'] = $data->result_count();
         }
         $final['users'] = array();
         foreach ($data as $user) {
             $final['users'][] = $user->to_array($params);
         }
     } else {
         $user = $u->get_by_id($id);
         if ($u->exists()) {
             $final = $user->to_array($params);
         } else {
             $this->error('404', "User with ID: {$id} not found.");
             return;
         }
     }
     $this->set_response_data($final);
 }