Adding Ion Auth authentication library in a Codeigniter Framework

A

Ion Auth is a simple and lightweight authentication library for the CodeIgniter framework.

Installation

  1. Download the latest version: http://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/2
  2. Copy the files from this package to the correspoding folder in your application folder. For example, copy Ion_auth/config/ion_auth.php to system/application/config/ion_auth.php.
  3. You can also copy the entire directory structure into your third_party/ folder. For example, copy everything to /application/third_party/ion_auth/
  4. Run the appropriate SQL file from the /sql directory.
  5. You load Ion Auth just link any other library: $this->load->library(“ion_auth”); from your controller.You can also autoload the library from autoload.php:$autoload[‘libraries’] = array(‘database’,’ion_auth’);
  6. You can also autoload the library from autoload.php :$autoload[‘libraries’] = array(‘database’,’ion_auth’);

The default login is:

  • Email: admin@admin.com
  • Password: password

Class Function In Ion Auth

1. login()

Logs the user into the system.

Parameters

  1. ‘Identity’ – string REQUIRED. Username, email or any unique value in your users table, depending on your configuration.
  2. ‘Password’ – string REQUIRED.
  3. ‘Remember’ – boolean OPTIONAL.

2. logout()

Logs the user out of the system.

3. register()

Create a new user.

Parameters

  1. ‘Identity’ – string REQUIRED. This must be the value that uniquely identifies the user when he is registered. If you chose “email” as $config[‘identity’] in the configuration file, you must put the email of the new user.
  2. ‘Password’ – string REQUIRED.
  3. ‘Email’ – string REQUIRED.
  4. ‘Additional Data’ – multidimensional array OPTIONAL.
  5. ‘Group’ – array OPTIONAL. If not passed the default group name set in the config will be used.

4. update()

Update a user.

Parameters

  1. ‘Id’ – integer REQUIRED.
  2. ‘Data’ – multidimensional array REQUIRED.

5. delete_user()

Delete a user.

Parameters

  1. ‘Id’ – integer REQUIRED.

7.forgotten_password()

Resets a users password by emailing the user a reset code.

Parameters

  1. ‘Identity’ – string REQUIRED. (as defined in config/ion_auth.php)

8. forgotten_password_complete()

Final step of resetting a users password. The user comes to this page from their email.

Parameters

  1. ‘Code’ – string REQUIRED.

9. logged_in()

Check to see if a user is logged in.

10. is_admin()

Check to see if the currently logged in user is an admin.

Parameters

  1. ‘id’ – integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.

11. in_group()

Check to see if the currently logged in user is in the passed in group.

Parameters

  1. ‘Group ID or Name’ – string, integer or array of strings and integers REQUIRED.
  2. ‘User ID’ – integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.

12. username_check()

Check to see if the username is already registered.

Parameters

  1. ‘Username’ – string REQUIRED.

13. email_check()

Check to see if the email is already registered.

Parameters

  1. ‘Email’ – string REQUIRED.

14. identity_check()

Check to see if the identity is already registered.

Parameters

  1. ‘Identity’ – string REQUIRED.

15. is_max_login_attempts_exceeded()

If login attempt tracking is enabled, checks to see if the number of failed login attempts for this identity or ip address has been exceeded. The controller must call this method and take any necessary actions. Login attempt limits are not enforced in the library.

Parameters

  1. ‘Identity’ – string REQUIRED.

16 User()

Get a user.

Parameters

  1. ‘Id’ – integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.

17. users()

Get the users.

Parameters

  1. ‘Group IDs’ – array OPTIONAL. If an array of group ids are passed (or a single group id) this will return the users in those groups.

18. group()

Get a group.

Parameters

  1. ‘Id’ – integer REQUIRED.

19. groups()

Get the groups.

20. messages()

Get messages.

21. get_users_groups()

Get all groups a user is part of.

Parameters

  1. ‘Id’ – integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.

22. add_to_group()

Add user to group

Parameters

  1. ‘Group_id’ – integer or array REQUIRED.
  2. ‘User_id’ – integer REQUIRED.

23. remove_from_group()

Remove user from group(s)

Parameters

  1. ‘Group_id’ – NULL, integer or array REQUIRED. NULL will remove the user from all groups.
  2. ‘User_id’ – integer REQUIRED.

24. create_group()

Create a group

Parameters

  1. ‘group_name’ – string REQUIRED.
  2. ‘group_description’ – string.

25. update_group()

Update details of a group

Parameters

  1. ‘group_id’ – int REQUIRED.
  2. ‘group_name’ – string REQUIRED.
  3. ‘group_description’ – string.

26. delete_group()

Remove a group. Removes the group details from the configured ‘groups’ table. Users belonging to the group are stripped of this status (references to this group are removed from users_groups), but user data itself remains untouched.

Parameters

  1. ‘group_id’ – int REQUIRED.

28. errors()

Get the errors.

29. set_hook()

Set a single or multiple functions to be called when trigged by trigger_events(). See an example here: http://gist.github.com/657de89b26decda2b2fa

Parameters

  1. ‘Event’ – string REQUIRED.
  2. ‘Name’ – string REQUIRED.
  3. ‘Class’ – string REQUIRED.
  4. ‘Method’ – string REQUIRED.
  5. ‘Arguments’ – Array OPTIONAL.

30. trigger_events()

Call Additional functions to run that were registered with set_hook().

Parameters

  1. ‘Name’ – String or Array REQUIRED.

 

 

About the author

Islam Shaikh
By Islam Shaikh

Category