⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

For users that use ion auth with ci and gc



Robert
  • profile picture
  • Member

Posted 02 July 2013 - 11:26 AM

I have a table where users log in and add records and i want them to see only what they added. For the filters i use the code :

$user = $this->ion_auth->user()->row();
if ($user->id == '1')
{
         $crud->where('cod_id','1');
}
elseif ($user->id == '2')
{
         $crud->where('cod_id','2');
}
... where cod_id is the id from user. Now the hard part for me is to add the id automatic when a user adds records to the table. Any ideas ? how can i insert the user id from the users to the cod_id of my table ..

 

 

Thanks for you help if anyone know how to do it.


davidoster
  • profile picture
  • Member

Posted 03 July 2013 - 00:43 AM

$user = $this->ion_auth->user()->row();

$crud->where('cod_id', $user->id);

 

Please Robert take some PHP programming lessons. These are elementary.


Robert
  • profile picture
  • Member

Posted 03 July 2013 - 06:03 AM

thanks  davidoster. i have started with tutorials.


Pakman
  • profile picture
  • Member

Posted 03 September 2013 - 23:35 PM

$user = $this->ion_auth->user()->row();

$crud->where('cod_id', $user->id);

 

Please Robert take some PHP programming lessons. These are elementary.

 

How I can prevent a user can edit the data of another user? If I change the url (/ edit / xxxxx) I can edit any record, even those that are filtered.


davidoster
  • profile picture
  • Member

Posted 04 September 2013 - 00:56 AM

How I can prevent a user can edit the data of another user? If I change the url (/ edit / xxxxx) I can edit any record, even those that are filtered.

 

You need to also have something like this,

if($user->id == x) $crud->unset_edit();


Pakman
  • profile picture
  • Member

Posted 04 September 2013 - 07:03 AM

 

You need to also have something like this,

if($user->id == x) $crud->unset_edit();

 

 

Ok davidoster, where I put this line? I'm a beginner! :D


Robert
  • profile picture
  • Member

Posted 04 September 2013 - 08:39 AM

Here you go

// initiate
$user = $this->ion_auth->user()->row();

// filter
if($user->id == 'xx')   {
    $crud->unset_edit();
}

xx = from table users - the id


davidoster
  • profile picture
  • Member

Posted 04 September 2013 - 08:45 AM

Here you go

// initiate
$user = $this->ion_auth->user()->row();

// filter
if($user->id == 'xx')   {
    $crud->unset_edit();
}

xx = from table users - the id

 

 

Ok davidoster, where I put this line? I'm a beginner! :D

 

[member=pakman] use this code on your controller's function, where the grocery crud code is and you want to protect it from.

E.g. you have a table customers and a controller function public function customers().

This is where you put this code.


Pakman
  • profile picture
  • Member

Posted 04 September 2013 - 14:09 PM

Thank you all but I can not get it to work. If I have several users and they change the code in the url (edit/xxx) can edit records that are not yours. With this I have a filter, but if the customer with id =1 type url 'edit/3' he can edit the information of customer 3. :( Well, edit, delete...

	public function customers()
	{
		$crud = new grocery_CRUD();
                $crud->where('id', $customer_id);
		$crud->set_table('customers');
    	        $output = $crud->render();
	    	$this->_example_output($output);	    			

	}

Pakman
  • profile picture
  • Member

Posted 04 September 2013 - 14:52 PM

Well, I found some information here: /topic/2019-where-problems/


Robert
  • profile picture
  • Member

Posted 04 September 2013 - 19:20 PM

Seams you are right ... didn't know about that until now  :)


Amit Shah
  • profile picture
  • Member

Posted 05 September 2013 - 12:21 PM

Welll..

here is a solution to the same you can look into it..

what you can do is..

when the $crud->getState() - is edit...

get the user id

get the primary key of the row that is being edited (explore the getstateinfo function for the same - u should get it as primary_key value)

then compare .. if the users id is the same as the rows id... then only allow him to edit

else show error / take necessary action.


mnish
  • profile picture
  • Member

Posted 06 September 2013 - 17:35 PM

Seams you are right ... didn't know about that until now  :)

 

Don't take tension my friend Here is the solution /topic/2019-where-problems/#entry9376


Pakman
  • profile picture
  • Member

Posted 08 September 2013 - 08:30 AM

Thanks mnish!