CodeIgniter 2 and Ion Auth - edit own user account CodeIgniter 2 and Ion Auth - edit own user account codeigniter codeigniter

CodeIgniter 2 and Ion Auth - edit own user account


Unless I'm missing something, I ended up modifying the edit_user function within the auth.php Controller as follows.

I changed this line which checks to see that the user is "not logged in" OR "not an admin" before dumping them out...

if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin()){    redirect('auth', 'refresh');}

...into this, which check to see that the user is "not logged in" OR ("not an admin" AND "not the user") before dumping them out...

if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !($this->ion_auth->user()->row()->id == $id)))

This seems to be working...

  • Admin can edit all accounts
  • User can only edit his own account
  • and somebody not logged in, can't edit any account.

Edit: However, the user also has access to the "groups" setting and could simply put themself into the "admin" group. Not good.

Ion Auth's developer refers to the files he provides as working "examples". Therefore, it's up to the end-developer to edit Ion Auth to suit the needs of the project.

To prevent the user from being able to make himself an "admin" requires a simple change to the edit_user.php view file.

Verifies the user is already an "admin" before creating the checkboxes...

<?php if ($this->ion_auth->is_admin()): ?>    // code that generates Groups checkboxes<?php endif ?>

Then you'll also need to thoroughly test and adjust as needed. For example, after editing a user profile, you're redirected to the auth view. Since the user doesn't have permission to see the auth view, there is a "must be an admin" error. In the controller file, you'll have to add the appropriate logic to properly redirect the user when they're not an "admin".


No Ion Auth doesn't do this as is - it's pretty light weight. But it's not hard to do and your on the right track, just grab that edit_user method and take out the admin checks and make it so the user can only edit their own account, just alter it so that it only updates user details for the currently logged in user.

Check the ion auth docs, have a crack at it and come back with some code if you have any problems.