### Get All Users Source: https://benedmunds.com/ion_auth Fetches all users from the system. The result is typically an array of user objects. ```php $users = $this->ion_auth->users()->result(); // get all users ``` -------------------------------- ### Initiate Password Reset Source: https://benedmunds.com/ion_auth This example shows how to handle the forgotten password form submission, validating input and calling the Ion Auth forgotten_password method. ```php //Working code for this example is in the example Auth controller in the github repo function forgot_password() { $this->form_validation->set_rules('email', 'Email Address', 'required'); if ($this->form_validation->run() == false) { //setup the input $this->data['email'] = array('name' => 'email', 'id' => 'email', ); //set any errors and display the form $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); $this->load->view('auth/forgot_password', $this->data); } else { //run the forgotten password method to email an activation code to the user $forgotten = $this->ion_auth->forgotten_password($this->input->post('email')); if ($forgotten) { //if there were no errors $this->session->set_flashdata('message', $this->ion_auth->messages()); redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page } else { $this->session->set_flashdata('message', $this->ion_auth->errors()); redirect("auth/forgot_password", 'refresh'); } } } ``` -------------------------------- ### Get User Messages as String Source: https://benedmunds.com/ion_auth Retrieve user-related messages as a single string. Useful for displaying feedback after an update operation. ```php $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); if ($this->ion_auth->update_user($id, $data)) { $messages = $this->ion_auth->messages(); echo $messages; } else { $errors = $this->ion_auth->errors(); echo $errors; } ``` -------------------------------- ### Get All Groups Source: https://benedmunds.com/ion_auth Fetches all available groups within the system. The return value is an array of group objects, each containing group details. ```php $groups = $this->ion_auth->groups()->result(); ``` -------------------------------- ### Get Users by Mixed Group IDs and Names Source: https://benedmunds.com/ion_auth Fetches users from a combination of specified group IDs and names. This provides flexibility in querying users across various group criteria. ```php $users = $this->ion_auth->users(array('admin',4,'members'))->result(); // get users from 'admin' group, 'members' group and group with id '4' ``` -------------------------------- ### Get Users by Group Name Source: https://benedmunds.com/ion_auth Fetches users who are members of a specified group, identified by its name. This allows for easy retrieval of users based on group roles. ```php $users = $this->ion_auth->users('members')->result(); // get users from 'members' group ``` -------------------------------- ### Get Group Details by ID Source: https://benedmunds.com/ion_auth Retrieves details for a specific group using its ID. The result is an object containing information about the group. ```php $group_id = 2; $group = $this->ion_auth->group($group_id)->result(); ``` -------------------------------- ### Get Users by Multiple Group Names Source: https://benedmunds.com/ion_auth Retrieves users who belong to one or more specified groups, identified by their names. This is useful for fetching users across different roles. ```php $users = $this->ion_auth->users(array('admin','members'))->result(); // get users from 'admin' and 'members' group ``` -------------------------------- ### Get Single User Details Source: https://benedmunds.com/ion_auth Retrieves details for a specific user by their ID, or the currently logged-in user if no ID is provided. The returned object contains user properties like email, username, etc. ```php $user = $this->ion_auth->user()->row(); echo $user->email; ``` -------------------------------- ### Get Number of Login Attempts Source: https://benedmunds.com/ion_auth Retrieves the count of failed login attempts for a given identity or IP address. This is useful for monitoring or displaying attempt counts. ```php $identity = 'ben.edmunds@gmail.com'; $num_attempts = $this->ion_auth->get_attempts_num($identity); ``` -------------------------------- ### Get User's Groups Source: https://benedmunds.com/ion_auth Retrieve all groups a specific user belongs to. If no user ID is provided, it defaults to the currently logged-in user. ```php $user_groups = $this->ion_auth->get_users_groups($user->id)->result(); ``` -------------------------------- ### Get User Messages as Array Source: https://benedmunds.com/ion_auth Retrieve user-related messages as an array. Allows for iterating through individual messages, potentially for internationalization. ```php $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); if ($this->ion_auth->update_user($id, $data)) { $messages = $this->ion_auth->messages_array(); foreach ($messages as $message) { echo $message; } } else { $errors = $this->ion_auth->errors_array(); foreach ($errors as $error) { echo $error; } } ``` -------------------------------- ### Get Error Messages as Array Source: https://benedmunds.com/ion_auth Retrieve error messages as an array, allowing for individual processing of each error. Optionally, messages can be langified. ```PHP $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); if ($this->ion_auth->update_user($id, $data)) { $messages = $this->ion_auth->messages_array(); foreach ($messages as $message) { echo $message; } } else { $errors = $this->ion_auth->errors_array(); foreach ($errors as $error) { echo $error; } } ``` -------------------------------- ### Get Error Messages Source: https://benedmunds.com/ion_auth Retrieve all error messages generated by the Ion Auth library. This function returns errors as a single string. ```PHP $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); if ($this->ion_auth->update_user($id, $data)) { $messages = $this->ion_auth->messages(); echo $messages; } else { $errors = $this->ion_auth->errors(); echo $errors; } ``` -------------------------------- ### Get Users by Group ID Source: https://benedmunds.com/ion_auth Retrieves users belonging to a specific group identified by its ID. This is useful for filtering users based on their group membership. ```php $users = $this->ion_auth->users(1)->result(); // get users from group with id of '1' ``` -------------------------------- ### Update User if Identity Check Passes Source: https://benedmunds.com/ion_auth Checks if an identity (username or email) is already registered or if the provided identity matches the current user's identity before updating the user. This is a basic example and typically used with form validation. ```php //This is a lame example but it works. $user = $this->ion_auth->user(); $data = array( 'identity' => $this->input->post('identity'), 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), ); if ($data['identity'] === $user->username || $data['identity'] === $user->email || $this->ion_auth->identity_check($data['identity']) === FALSE) { $this->ion_auth->update_user($user->id, $data) } ``` -------------------------------- ### login() Source: https://benedmunds.com/ion_auth Logs the user into the system. It takes the user's identity, password, and an optional remember flag as parameters. ```APIDOC ## login() ### Description Logs the user into the system. ### Method POST (inferred) ### Endpoint /login (inferred) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **identity** (string) - Required. Username, email or any unique value in your users table, depending on your configuration. - **password** (string) - Required. - **remember** (boolean) - Optional. TRUE sets the user to be remembered if enabled in the configuration. ### Request Example ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; $remember = TRUE; // remember the user $this->ion_auth->login($identity, $password, $remember); ``` ### Response #### Success Response (200) - **boolean** (boolean) - TRUE if the user was successfully logged in. #### Error Response (401) - **boolean** (boolean) - FALSE if the user was not logged in. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### register() Source: https://benedmunds.com/ion_auth Register (create) a new user with provided credentials and optional data. ```APIDOC ## register() ### Description Register (create) a new user. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **Identity** (string) - REQUIRED. Unique identifier for the user (e.g., email or username). - **Password** (string) - REQUIRED. - **Email** (string) - REQUIRED. - **Additional Data** (multidimensional array) - OPTIONAL. Additional user information. - **Group** (array) - OPTIONAL. User group assignment. Defaults to the group name set in the configuration. ### Request Example ```php $this->ion_auth->register($username, $password, $email, $additional_data, $group); ``` ### Response #### Success Response - Returns the ID of the user if successfully created. #### Error Response - Returns FALSE if the user was not created. #### Response Example ```php // Success: 123 (user ID) // Failure: false ``` ``` -------------------------------- ### create_user() Source: https://benedmunds.com/ion_auth An alternate method for registering a new user. ```APIDOC ## create_user() ### Description An alternate method for the `register()` method. ### Parameters (Same as `register()`) ### Response (Same as `register()`) ``` -------------------------------- ### Register a New User Source: https://benedmunds.com/ion_auth Use this snippet to create a new user with their identity, password, email, optional additional data, and group. ```php $username = 'benedmunds'; $password = '12345678'; $email = 'ben.edmunds@gmail.com'; $additional_data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); $group = array('1'); // Sets user to admin. $this->ion_auth->register($username, $password, $email, $additional_data, $group) ``` -------------------------------- ### Create a New Group Source: https://benedmunds.com/ion_auth Create a new group with a name and an optional description. Returns the new group ID on success or FALSE on failure. ```php // pass the right arguments and it's done $group = $this->ion_auth->create_group('new_test_group', 'This is a test description'); if(!$group) { $view_errors = $this->ion_auth->messages(); } else { $new_group_id = $group; // do more cool stuff } ``` -------------------------------- ### Login User Source: https://benedmunds.com/ion_auth Logs a user into the system. Use this to authenticate users. The 'remember' parameter can be set to TRUE to enable the 'remember me' functionality if configured. ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; $remember = TRUE; // remember the user $this->ion_auth->login($identity, $password, $remember); ``` -------------------------------- ### Load Ion Auth Library Source: https://benedmunds.com/ion_auth Load the Ion Auth library using CodeIgniter's loader. Ensure your database connection is loaded first, or configure autoloading. ```php $this->load->library('ion_auth'); ``` -------------------------------- ### create_group() Source: https://benedmunds.com/ion_auth Creates a new group within the system. Requires a group name and optionally accepts a group description. ```APIDOC ## create_group() ### Description Create a group. ### Parameters * 'group_name' - string REQUIRED. * 'group_description' - string. ### Return * brand new group_id if the group was created, FALSE if the group creation failed. ### Usage ```php $group = $this->ion_auth->create_group('new_test_group', 'This is a test description'); if(!$group) { $view_errors = $this->ion_auth->messages(); } else { $new_group_id = $group; } ``` ``` -------------------------------- ### groups() Source: https://benedmunds.com/ion_auth Retrieves a list of all available groups. ```APIDOC ## groups() ### Description Get the groups. ### Return - **array of objects**. An array where each element is an object representing a group. ### Usage Example ```php $groups = $this->ion_auth->groups()->result(); ``` ``` -------------------------------- ### logout() Source: https://benedmunds.com/ion_auth Logs the user out of the system. This method does not require any parameters. ```APIDOC ## logout() ### Description Logs the user out of the system. ### Method POST (inferred) ### Endpoint /logout (inferred) ### Parameters None ### Request Example ```php $this->ion_auth->logout(); ``` ### Response #### Success Response (200) - **boolean** (boolean) - TRUE if the user was successfully logged out. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### update() Source: https://benedmunds.com/ion_auth Update an existing user's information. ```APIDOC ## update() ### Description Update a user. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **Id** (integer) - REQUIRED. The ID of the user to update. - **Data** (multidimensional array) - REQUIRED. An array containing the user data to update. ### Request Example ```php $this->ion_auth->update($id, $data); ``` ### Response #### Success Response - Returns TRUE if the user was successfully updated. #### Error Response - Returns FALSE if the user was not updated. #### Response Example ```php // Success: true // Failure: false ``` ``` -------------------------------- ### Check User Group Membership (Multiple by ID and Name) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to at least one of the specified groups, which can be identified by either ID or name. Redirects if the user is not in any of the groups. ```php # multiple groups (by id and name) $group = array('gangstas', 2); if (!$this->ion_auth->in_group($group)) $this->session->set_flashdata('message', 'You must be a part of the gangstas or group 2'); redirect('welcome/index'); } ``` -------------------------------- ### Check User Group Membership (All Groups by ID) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to all of the specified groups identified by their IDs. Redirects if the user is not in all of the groups. ```php # multiple groups (by id) and check if all exist $group = array(1, 2); if (!$this->ion_auth->in_group($group, false, true)) $this->session->set_flashdata('message', 'You must be a part of group 1 and 2 to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### Add User to Group(s) Source: https://benedmunds.com/ion_auth Add a user to one or more groups. Accepts a single group ID or an array of group IDs. ```php // pass an array of group ID's and user ID $this->ion_auth->add_to_group(array('1', '3', '6'), $user_id); // pass a single ID and user ID $this->ion_auth->add_to_group(1, $user_id); ``` -------------------------------- ### Check User Group Membership (Single by Name) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to a specific group identified by its name. Redirects if the user is not in the group. ```php # single group (by name) $group = 'gangstas'; if (!$this->ion_auth->in_group($group)) { $this->session->set_flashdata('message', 'You must be a gangsta to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### Check User Group Membership (Multiple by Name) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to at least one of the specified groups identified by their names. Redirects if the user is not in any of the groups. ```php # multiple groups (by name) $group = array('gangstas', 'hoodrats'); if (!$this->ion_auth->in_group($group)) $this->session->set_flashdata('message', 'You must be a gangsta OR a hoodrat to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### forgotten_password() Source: https://benedmunds.com/ion_auth Initiates the password reset process by emailing the user a reset code. ```APIDOC ## forgotten_password() ### Description Resets a user's password by emailing the user a reset code. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **Identity** (string) - REQUIRED. The user's identity (e.g., email or username) as defined in the configuration. ### Request Example ```php $this->ion_auth->forgotten_password($this->input->post('email')); ``` ### Response #### Success Response - Returns TRUE if the user's password was successfully reset. #### Error Response - Returns FALSE if the user's password was not reset. #### Response Example ```php // Success: true // Failure: false ``` ``` -------------------------------- ### Register New User if Email Not Found Source: https://benedmunds.com/ion_auth Checks if an email address is already registered before attempting to register a new user. This is often used in conjunction with form validation. ```php //This is a lame example but it works. Usually you would use this method with form_validation. $username = $this->input->post('username'); $password = $this->input->post('password'); $email = $this->input->post('email'); $additional_data = array( 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), ); if (!$this->ion_auth->email_check($email)) { $group_name = 'users'; $this->ion_auth->register($username, $password, $email, $additional_data, $group_name) } ``` -------------------------------- ### Register New User if Username Not Found Source: https://benedmunds.com/ion_auth Checks if a username is already registered before attempting to register a new user. This is often used in conjunction with form validation. ```php //This is a lame example but it works. Usually you would use this method with form_validation. $username = $this->input->post('username'); $password = $this->input->post('password'); $email = $this->input->post('email'); $additional_data = array( 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), ); if (!$this->ion_auth->username_check($username)) { $group_name = 'users'; $this->ion_auth->register($username, $password, $email, $additional_data, $group_name) } ``` -------------------------------- ### Check User Group Membership (Single by ID) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to a specific group identified by its ID. Redirects if the user is not in the group. ```php # single group (by id) $group = 1; if (!$this->ion_auth->in_group($group)) { $this->session->set_flashdata('message', 'You must be part of the group 1 to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### update_user() Source: https://benedmunds.com/ion_auth An alternate method for updating user information. ```APIDOC ## update_user() ### Description An alternate method for the `update()` method. ### Parameters (Same as `update()`) ### Response (Same as `update()`) ``` -------------------------------- ### Check User Group Membership (Multiple by ID) Source: https://benedmunds.com/ion_auth Use this to verify if a user belongs to at least one of the specified groups identified by their IDs. Redirects if the user is not in any of the groups. ```php # multiple groups (by id) $group = array(1, 2); if (!$this->ion_auth->in_group($group)) $this->session->set_flashdata('message', 'You must be a part of group 1 or 2 to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### Update Group Details Source: https://benedmunds.com/ion_auth Update the name and/or description of an existing group. Requires the group ID and new name, with an optional array for additional data like description. ```php // source these things from anywhere you like (eg., a form) $group_id = 2; $group_name = 'test_group_changed_name'; $additional_data = array( 'description' => 'New Description' ); // pass the right arguments and it's done $group_update = $this->ion_auth->update_group($group_id, $group_name, $additional_data); if(!$group_update) { $view_errors = $this->ion_auth->messages(); } else { // do more cool stuff } ``` -------------------------------- ### increase_login_attempts() Source: https://benedmunds.com/ion_auth Records an additional failed login attempt for a given identity or IP address, if login attempt tracking is active. This is typically called automatically when a login attempt fails. ```APIDOC ## increase_login_attempts() ### Description If login attempt tracking is enabled, records another failed login attempt for this identity or ip address. This method is automatically called during the login() method if the login failed. ### Parameters #### Path Parameters - **Identity** (string) - REQUIRED. The identity or IP address that failed to log in. ### Usage Example ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; if ($this->ion_auth->login($identity, $password) == FALSE) { $this->ion_auth->increase_login_attempts($identity); } ``` ``` -------------------------------- ### username_check() Source: https://benedmunds.com/ion_auth Verifies if a given username is already registered in the system. This is useful for ensuring unique usernames during registration. ```APIDOC ## username_check() ### Description Checks to see if the provided username is already registered in the system. Returns TRUE if the username exists, and FALSE otherwise. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **Username** (string) - REQUIRED. The username to check for registration. ### Return - boolean. TRUE if the user is registered, FALSE if the user is not registered. ``` -------------------------------- ### Set Message Delimiters Source: https://benedmunds.com/ion_auth Customize the delimiters used for success messages. Useful for wrapping messages in HTML tags like paragraphs or strong elements. ```PHP $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', ); if ($this->ion_auth->update_user($id, $data)) { $this->ion_auth->set_message_delimiters('
','
'); $messages = $this->ion_auth->messages(); echo $messages; } else { $this->ion_auth->set_error_delimiters('','
'); $errors = $this->ion_auth->errors(); echo $errors; } ``` -------------------------------- ### Trigger Events Source: https://benedmunds.com/ion_auth Execute all functions that have been registered with a specific event name using set_hook(). This is used to run custom callbacks. ```PHP $this->ion_auth->trigger_events('socialpush'); ``` -------------------------------- ### users() Source: https://benedmunds.com/ion_auth Retrieves a list of users, optionally filtered by group IDs or names. ```APIDOC ## users() ### Description Get the users. ### Parameters #### Path Parameters - **Group IDs, group names, or group IDs and names** (array) - OPTIONAL. If an array of group ids, of group names, or of group ids and names are passed (or a single group id or name), this will return the users in those groups. ### Return - **model object**. An iterable object containing user data. ### Usage Examples ```php // Get all users $users = $this->ion_auth->users()->result(); // Get users from group with id of '1' $users = $this->ion_auth->users(1)->result(); // Get users from 'members' group $users = $this->ion_auth->users('members')->result(); // Get users from 'admin' and 'members' groups $users = $this->ion_auth->users(array('admin','members'))->result(); // Get users from 'admin' group, 'members' group and group with id '4' $users = $this->ion_auth->users(array('admin',4,'members'))->result(); ``` ``` -------------------------------- ### Update User Information Source: https://benedmunds.com/ion_auth Update an existing user's details by providing their ID and an array of data to modify. ```php $id = 12; $data = array( 'first_name' => 'Ben', 'last_name' => 'Edmunds', 'password' => '123456789', ); $this->ion_auth->update($id, $data) ``` -------------------------------- ### Logout User Source: https://benedmunds.com/ion_auth Logs the current user out of the system. This is a simple function to end the user's session. ```php $this->ion_auth->logout(); ``` -------------------------------- ### Increase Login Attempts Source: https://benedmunds.com/ion_auth Records an additional failed login attempt for an identity or IP address. This method is automatically invoked by the login() method upon a failed login. ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; if ($this->ion_auth->login($identity, $password) == FALSE) { $this->ion_auth->increase_login_attempts($identity) } ``` -------------------------------- ### set_message_delimiters() Source: https://benedmunds.com/ion_auth Sets the delimiters for success messages. This allows for custom formatting of messages returned by the library. ```APIDOC ## set_message_delimiters() ### Description Sets the delimiters for success messages. ### Parameters #### Path Parameters - **Start Delimiter** (string) - REQUIRED - The starting delimiter for messages. - **End Delimiter** (string) - REQUIRED - The ending delimiter for messages. ``` -------------------------------- ### trigger_events() Source: https://benedmunds.com/ion_auth Executes all registered functions for a given event name. ```APIDOC ## trigger_events() ### Description Call Additional functions to run that were registered with set_hook(). ### Parameters #### Path Parameters - **Name** (String or Array) - REQUIRED - The name of the event(s) to trigger. ``` -------------------------------- ### is_max_login_attempts_exceeded() Source: https://benedmunds.com/ion_auth Checks if the maximum number of failed login attempts has been exceeded for a given identity or IP address. This function does not enforce limits; it only checks the status. ```APIDOC ## is_max_login_attempts_exceeded() ### Description 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 #### Path Parameters - **Identity** (string) - REQUIRED. The identity or IP address to check. ### Return - **boolean**. TRUE if maximum_login_attempts is exceeded, FALSE if not or if login attempts are not tracked. ### Usage Example ```php $identity = 'ben.edmunds@gmail.com'; if ($this->ion_auth->is_max_login_attempts_exceeded($identity)) { $this->session->set_flashdata('message', 'You have too many login attempts'); redirect('welcome/index'); } ``` ``` -------------------------------- ### Set Event Hooks Source: https://benedmunds.com/ion_auth Register functions to be called when specific events are triggered. This allows for custom logic execution at various points in the application flow. ```PHP class Accounts extends CI_Controller { public function __construct() { parent::__construct(); /* make sure we loaded ion_auth2 The following does not need to go in __construct() it just needs to be set before you trigger_events(). */ $event = 'socialpush'; $class = 'Accounts'; $args = array('this is the content of the message', 'billy'); $name = 'activate_sendmail'; $method = 'email'; $this->ion_auth->set_hook($event, $name, $class, $method, $args); $name = 'call_Twitter'; $method = 'twitter'; $this->ion_auth->set_hook($event, $name, $class, $method, $args); $name = 'call_MailChimp_API'; $method = 'mailchimp'; $this->ion_auth->set_hook($event, $name, $class, $method, $args); $name = 'call_Facebook_API'; $method = 'facebook'; $this->ion_auth->set_hook($event, $name, $class, $method, $args); $name = 'call_gPlus_API'; $method = 'gplus'; $this->ion_auth->set_hook($event, $name, $class, $method, $args); } public function Post_Message($one) { $this->ion_auth->trigger_events('socialpush'); } public function email($content, $who) { return true; } public function twitter($content, $who) { return true; } public function mailchimp($content, $who) { return true; } public function facebook($content, $who) { return true; } public function gplus($content, $who) { return true; } } ``` -------------------------------- ### user() Source: https://benedmunds.com/ion_auth Retrieves a specific user's details. If no user ID is provided, it defaults to the currently logged-in user. ```APIDOC ## user() ### Description Get a user. ### Parameters #### Path Parameters - **Id** (integer) - OPTIONAL. If a user id is not passed, the id of the currently logged in user will be used. ### Return - **stdClass Object**. An object containing the user's details. ### Usage Example ```php $user = $this->ion_auth->user()->row(); echo $user->email; ``` ``` -------------------------------- ### Check if User is Admin Source: https://benedmunds.com/ion_auth Ensures the current user has admin privileges before allowing access to a page. Redirects to the welcome page with a message if not an admin. ```php if (!$this->ion_auth->is_admin()) { $this->session->set_flashdata('message', 'You must be an admin to view this page'); redirect('welcome/index'); } ``` -------------------------------- ### in_group() Source: https://benedmunds.com/ion_auth Checks if a user belongs to one or more specified groups. It can verify membership in any of the provided groups or require membership in all of them. ```APIDOC ## in_group() ### Description Checks to see if a user is in a group(s). This function can be used to verify if a user belongs to any of the specified groups or if they belong to all of them. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **Group ID or Name** (string) - REQUIRED. Can be a single group ID (integer) or name (string), or an array of group IDs and names. - **User ID** (integer) - OPTIONAL. If not provided, the ID of the currently logged-in user is used. - **Check All** (boolean) - OPTIONAL. If TRUE, checks if the user is in all specified groups. If FALSE (default), checks if the user is in any of the specified groups. ### Return - boolean. TRUE if the user meets the group criteria, FALSE otherwise. ``` -------------------------------- ### Check Forgotten Password Code Source: https://benedmunds.com/ion_auth Verify if a provided forgotten password code is valid. Returns user data if valid, or false otherwise. ```php $user = $this->ion_auth->forgotten_password_check($code); if ($user) { //display the password reset form } ``` -------------------------------- ### Check if User is Logged In Source: https://benedmunds.com/ion_auth Redirects to the login page if the user is not currently logged in. ```php if (!$this->ion_auth->logged_in()) { redirect('auth/login'); } ``` -------------------------------- ### errors() Source: https://benedmunds.com/ion_auth Retrieves any error messages generated by the library. Returns a string containing all errors. ```APIDOC ## errors() ### Description Gets the errors generated by the library. ### Return * string - A string containing all error messages. ``` -------------------------------- ### logged_in() Source: https://benedmunds.com/ion_auth Checks if a user is currently logged in. ```APIDOC ## logged_in() ### Description Check to see if a user is logged in. ### Parameters - None ### Response #### Success Response - Returns TRUE if the user is logged in. #### Error Response - Returns FALSE if the user is not logged in. #### Response Example ```php // Success: true // Failure: false ``` ``` -------------------------------- ### add_to_group() Source: https://benedmunds.com/ion_auth Adds a user to one or more specified groups. Returns a boolean indicating success or failure. ```APIDOC ## add_to_group() ### Description Add user to group. ### Parameters * 'Group_id' - integer or array REQUIRED. * 'User_id' - integer REQUIRED. ### Return * boolean. TRUE if the user was added to group(s) FALSE if the user is not added to group(s). ### Usage ```php // pass an array of group ID's and user ID $this->ion_auth->add_to_group(array('1', '3', '6'), $user_id); // pass a single ID and user ID $this->ion_auth->add_to_group(1, $user_id); ``` ``` -------------------------------- ### delete_user() Source: https://benedmunds.com/ion_auth Delete a user from the system. ```APIDOC ## delete_user() ### Description Delete a user. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **Id** (integer) - REQUIRED. The ID of the user to delete. ### Request Example ```php $this->ion_auth->delete_user($id); ``` ### Response #### Success Response - Returns TRUE if the user was successfully deleted. #### Error Response - Returns FALSE if the user was not deleted. #### Response Example ```php // Success: true // Failure: false ``` ``` -------------------------------- ### Check Login Attempts Exceeded Source: https://benedmunds.com/ion_auth Use this to check if the number of failed login attempts for an identity has been exceeded. The controller must call this method and take any necessary actions. ```php $identity = 'ben.edmunds@gmail.com'; if ($this->ion_auth->is_max_login_attempts_exceeded($identity)) { $this->session->set_flashdata('message', 'You have too many login attempts'); redirect('welcome/index'); } ``` -------------------------------- ### set_hook() Source: https://benedmunds.com/ion_auth Registers a function to be called when a specific event is triggered. Supports single or multiple functions. ```APIDOC ## set_hook() ### Description Set a single or multiple functions to be called when trigged by trigger_events(). ### Parameters #### Path Parameters - **Event** (string) - REQUIRED - The name of the event to hook into. - **Name** (string) - REQUIRED - The name of the hook. - **Class** (string) - REQUIRED - The class containing the method. - **Method** (string) - REQUIRED - The method to call. - **Arguments** (Array) - OPTIONAL - An array of arguments to pass to the method. ``` -------------------------------- ### group() Source: https://benedmunds.com/ion_auth Retrieves details for a specific group based on its ID. ```APIDOC ## group() ### Description Get a group. ### Parameters #### Path Parameters - **Id** (integer) - REQUIRED. The ID of the group to retrieve. ### Return - **object**. An object containing the group's details. ### Usage Example ```php $group_id = 2; $group = $this->ion_auth->group($group_id)->result(); ``` ``` -------------------------------- ### clear_login_attempts() Source: https://benedmunds.com/ion_auth Resets all failed login attempt records for a specified identity or IP address. This is usually called automatically upon a successful login. ```APIDOC ## clear_login_attempts() ### Description Clears all failed login attempt records for this identity or this ip address. This method is automatically called during the login() method if the login succeeded. ### Parameters #### Path Parameters - **Identity** (string) - REQUIRED. The identity or IP address for which to clear login attempts. ### Usage Example ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; if ($this->ion_auth->login($identity, $password) == TRUE) { $this->ion_auth->clear_login_attempts($identity); } ``` ``` -------------------------------- ### Delete a User Source: https://benedmunds.com/ion_auth Remove a user from the system by providing their user ID. ```php $id = 12; $this->ion_auth->delete_user($id) ``` -------------------------------- ### identity_check() Source: https://benedmunds.com/ion_auth Determines if a given identity string (which could be a username or email) is already in use by a registered user. ```APIDOC ## identity_check() ### Description Checks to see if the provided identity (username or email) is already registered in the system. Returns TRUE if the identity exists, and FALSE otherwise. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **Identity** (string) - REQUIRED. The identity string (username or email) to check for registration. ### Return - boolean. TRUE if the user is registered, FALSE if the user is not registered. ``` -------------------------------- ### forgotten_password_check() Source: https://benedmunds.com/ion_auth Verifies if a forgotten password reset code is valid. ```APIDOC ## forgotten_password_check() ### Description Check to see if the forgotten password code is valid. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **Code** (string) - REQUIRED. The forgotten password code to check. ### Request Example ```php $user = $this->ion_auth->forgotten_password_check($code); ``` ### Response #### Success Response - Returns the user record object if the code is valid. #### Error Response - Returns FALSE if the code is invalid. #### Response Example ```php // Success: object (user record) // Failure: false ``` ``` -------------------------------- ### get_users_groups() Source: https://benedmunds.com/ion_auth Retrieves all groups that a specific user is a part of. If no user ID is provided, it defaults to the currently logged-in user. ```APIDOC ## get_users_groups() ### Description Get all groups a user is part of. ### Parameters * 'Id' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used. ### Return * ```stdClass Object ( [id] => 1 [name] => admins [description] => Administrator ) ``` ### Usage ```php $user_groups = $this->ion_auth->get_users_groups($user->id)->result(); ``` ``` -------------------------------- ### Clear Login Attempts Source: https://benedmunds.com/ion_auth Resets all failed login attempt records for a specific identity or IP address. This is automatically called by the login() method upon a successful login. ```php $identity = 'ben.edmunds@gmail.com'; $password = '12345678'; if ($this->ion_auth->login($identity, $password) == TRUE) { $this->ion_auth->clear_login_attempts($identity) } ``` -------------------------------- ### messages() Source: https://benedmunds.com/ion_auth Retrieves messages from the Ion Auth library. These messages are typically status updates or error notifications. ```APIDOC ## messages() ### Description Get messages from the Ion Auth library. ### Return * string ### Usage ```php $messages = $this->ion_auth->messages(); echo $messages; ``` ``` -------------------------------- ### set_error_delimiters() Source: https://benedmunds.com/ion_auth Sets the delimiters for error messages. This allows for custom formatting of error messages returned by the library. ```APIDOC ## set_error_delimiters() ### Description Sets the delimiters for error messages. ### Parameters #### Path Parameters - **Start Delimiter** (string) - REQUIRED - The starting delimiter for error messages. - **End Delimiter** (string) - REQUIRED - The ending delimiter for error messages. ``` -------------------------------- ### update_group() Source: https://benedmunds.com/ion_auth Updates the details of an existing group, including its name and description. Returns a boolean indicating success or failure. ```APIDOC ## update_group() ### Description Update details of a group. ### Parameters * 'group_id' - int REQUIRED. * 'group_name' - string REQUIRED. * 'additional_data' - array. ### Return * boolean. TRUE if the group was updated, FALSE if the update failed. ### Usage ```php $group_id = 2; $group_name = 'test_group_changed_name'; $additional_data = array( 'description' => 'New Description' ); $group_update = $this->ion_auth->update_group($group_id, $group_name, $additional_data); if(!$group_update) { $view_errors = $this->ion_auth->messages(); } else { // do more cool stuff } ``` ``` -------------------------------- ### email_check() Source: https://benedmunds.com/ion_auth Checks if a given email address is already associated with a registered user. Ensures email uniqueness for new registrations. ```APIDOC ## email_check() ### Description Checks to see if the provided email address is already registered in the system. Returns TRUE if the email exists, and FALSE otherwise. ### Method Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **Email** (string) - REQUIRED. The email address to check for registration. ### Return - boolean. TRUE if the user is registered, FALSE if the user is not registered. ``` -------------------------------- ### is_admin() Source: https://benedmunds.com/ion_auth Determines if the currently logged-in user has administrator privileges. ```APIDOC ## is_admin() ### Description Check to see if the currently logged in user is an admin. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **id** (integer) - OPTIONAL. If not passed, the ID of the currently logged-in user will be used. ### Request Example ```php $this->ion_auth->is_admin(); ``` ### Response #### Success Response - Returns TRUE if the user is an admin. #### Error Response - Returns FALSE if the user is not an admin. #### Response Example ```php // Success: true // Failure: false ``` ``` -------------------------------- ### Remove User from Group(s) Source: https://benedmunds.com/ion_auth Remove a user from one or more groups. Can remove from specific groups, multiple groups, or all groups by passing NULL. ```php // pass an array of group ID's and user ID $this->ion_auth->remove_from_group(array('1', '3', '6'), $user_id); // pass a single ID and user ID $this->ion_auth->remove_from_group(1, $user_id); // pass NULL to remove user from all groups $this->ion_auth->remove_from_group(NULL, $user_id); ``` -------------------------------- ### messages_array() Source: https://benedmunds.com/ion_auth Retrieves messages from the Ion Auth library as an array. Allows for iterating through individual messages. ```APIDOC ## messages_array() ### Description Get messages as an array from the Ion Auth library. ### Parameters * 'Langify' - boolean OPTIONAL. TRUE means that the messages will be langified. ### Return * array ### Usage ```php $messages = $this->ion_auth->messages_array(); foreach ($messages as $message) { echo $message; } ``` ``` -------------------------------- ### get_attempts_num() Source: https://benedmunds.com/ion_auth Retrieves the current count of failed login attempts for a specified identity or IP address. ```APIDOC ## get_attempts_num() ### Description Returns the number of failed login attempts for this identity or ip address. ### Parameters #### Path Parameters - **Identity** (string) - REQUIRED. The identity or IP address for which to retrieve the attempt count. ### Return - **int**. The number of failed login attempts for the specified identity or IP address. ### Usage Example ```php $identity = 'ben.edmunds@gmail.com'; $num_attempts = $this->ion_auth->get_attempts_num($identity); ``` ``` -------------------------------- ### errors_array() Source: https://benedmunds.com/ion_auth Retrieves error messages as an array. This provides a structured way to access individual error messages. ```APIDOC ## errors_array() ### Description Gets error messages as an array. ### Parameters #### Query Parameters - **Langify** (boolean) - OPTIONAL - If true, error messages will be langified. ``` -------------------------------- ### Delete a Group Source: https://benedmunds.com/ion_auth Remove a group from the system. This also removes the group association from users but does not delete user data. ```php // source this from anywhere you like (eg., a form) $group_id = 2; // pass the right arguments and it's done $group_delete = $this->ion_auth->delete_group($group_id); if(!$group_delete) { $view_errors = $this->ion_auth->messages(); } else { // do more cool stuff } ```