Ion Auth is released under the Apache License v2.0. You can read the
license here: http://www.apache.org/licenses/LICENSE-2.0
Installation
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/
Email: admin@admin.com
Password: password
Upgrading
$this->load->library('ion_auth');
Configuration Options
$config['tables']['groups']
$config['tables']['users']
$config['tables']['users_groups']
$config['tables']['login_attempts']
$config['site_title']
$config['admin_email']
$config['default_group']
$config['admin_group']
$config['join']['users']
$config['join']['groups']
$config['identity']
$config['min_password_length']
$config['max_password_length']
$config['email_activation']
$config['remember_users']
$config['user_expire']
$config['user_extend_on_login']
$config['email_type']
$config['email_templates']
$config['email_activate']
$config['email_forgot_password']
$config['email_forgot_password_complete']
$config['salt_length']
$config['store_salt']
$config['forgot_password_expiration']
$config['track_login_attempts']
$config['maximum_login_attempts']
$config['message_start_delimiter']
$config['message_end_delimiter']
$config['error_start_delimiter']
$config['error_end_delimiter']
Using Config File
Config
'tables['groups']' - The table name to use for the groups table. DEFAULT is
'groups'.
'tables['users']' - The table name to use for the users table. DEFAULT is
'users'.
'tables['users_groups']' - The table name to use for the users groups table.
DEFAULT is 'users_groups'.
'join['users'] ' - Users table column you want to join WITH. DEFAULT is
'user_id'.
'join['groups'] ' - Group table column you want to join WITH. DEFAULT is
'group_id'.
'identity' - Column to use for uniquely identifing user/logging in/etc. Usual
choices are 'email' OR 'username'. You should add an index in the users
table for whatever you set this option to. DEFAULT is 'email'.
'user_expire' - Sets how long to remember the user for in seconds. Set to
zero for no expiration. DEFAULT is '86500'.
NOTE: Methods available in the model are called through the controller
using PHP5 magic. You should never use ion_auth_model->method() in your
applications.
login()
Parameters
Return
boolean. TRUE if the user was successfully logged in FALSE if the user was
not logged in.
Usage
$identity = 'ben.edmunds@gmail.com';
$password = '12345678';
logout()
Usage
$this->ion_auth->logout();
register()
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.
5. 'Group' - array OPTIONAL. If not passed the default group name set in the
config will be used.
Return
mixed. The ID of the user if the user was successfully created, FALSE if the
user was not created.
Usage
$username = 'benedmunds';
$password = '12345678';
$email = 'ben.edmunds@gmail.com';
$additional_data = array(
'last_name' =>
'Edmunds',
);
create_user()
update()
Update a user.
Parameters
Return
boolean. TRUE if the user was successfully updated FALSE if the user was
not updated.
Usage
$id = 12;
$data = array(
);
$this->ion_auth->update($id, $data)
delete_user()
Delete a user.
Parameters
Return
boolean. TRUE if the user was successfully deleted FALSE if the user was not
deleted.
Usage
$id = 12;
$this->ion_auth->delete_user($id)
forgotten_password()
Parameters
Return
boolean. TRUE if the users password was successfully reset FALSE if the
users password was not reset.
Usage
//Working code for this example is in the example Auth controller in the github repo
function forgot_password()
if ($this->form_validation->run() == false) {
'id'
);
$this->data['message'] = (validation_errors()) ?
validation_errors() : $this->session->flashdata('message');
$this->load->view('auth/forgot_password', $this->data);
else {
to the user
$forgotten = $this->ion_auth->forgotten_password($this-
>input->post('email'));
$this->session->set_flashdata('message', $this-
>ion_auth->messages());
}
else {
$this->session->set_flashdata('message', $this-
>ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
forgotten_password_complete()
Final step of resetting a users password. The user comes to this page from
their email.
Parameters
Return
Usage
//Working code for this example is in the example Auth controller in the github repo
public function reset_password($code)
$reset = $this->ion_auth->forgotten_password_complete($code);
if ($reset) { //if the reset worked then send them to the login page
$this->session->set_flashdata('message', $this->ion_auth-
>messages());
redirect("auth/login", 'refresh');
else { //if the reset didnt work then send them back to the forgot password
page
$this->session->set_flashdata('message', $this->ion_auth-
>errors());
redirect("auth/forgot_password", 'refresh');
logged_in()
Check to see if a user is logged in.
Return
boolean. TRUE if the user is logged in FALSE if the user is not logged in.
Usage
if (!$this->ion_auth->logged_in())
redirect('auth/login');
is_admin()
Parameters
Return
boolean. TRUE if the user is an admin FALSE if the user is not an admin.
Usage
if (!$this->ion_auth->is_admin())
this page');
redirect('welcome/index');
in_group()
Parameters
2. 'User ID' - integer OPTIONAL. If a user id is not passed the id of the currently
logged in user will be used.
Return
boolean. TRUE if the user is in any of the given groups, FALSE otherwise.
Usage
# single group (by name)
$group = 'gangstas';
if (!$this->ion_auth->in_group($group))
this page');
redirect('welcome/index');
$group = 1;
if (!$this->ion_auth->in_group($group))
redirect('welcome/index');
redirect('welcome/index');
if (!$this->ion_auth->in_group($group))
redirect('welcome/index');
if (!$this->ion_auth->in_group($group))
{
$this->session->set_flashdata('message', 'You must be a part of the
redirect('welcome/index');
username_check()
Parameters
Return
boolean. TRUE if the user is registered FALSE if the user is not registered.
Usage
//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(
>input->post('first_name'),
>input->post('last_name'),
);
if (!$this->ion_auth->username_check($username))
$group_name = 'users';
$additional_data, $group_name)
email_check()
Parameters
Return
boolean. TRUE if the user is registered FALSE if the user is not registered.
Usage
//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(
>input->post('first_name'),
>input->post('last_name'),
);
if (!$this->ion_auth->email_check($email))
$group_name = 'users';
$additional_data, $group_name)
}
identity_check()
Parameters
Return
boolean. TRUE if the user is registered FALSE if the user is not registered.
Usage
$user = $this->ion_auth->user();
$data = array(
);
{
$this->ion_auth->update_user($user->id, $data)
is_max_login_attempts_exceeded()
Parameters
Return
Usage
$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');
get_attempts_num()
Returns the number of failed login attempts for this identity or ip address.
Parameters
Return
int. The number of failed login attempts for this identity or ip address.
Usage
$identity = 'ben.edmunds@gmail.com';
$num_attempts = $this->ion_auth->get_attempts_num($identity);
increase_login_attempts()
Parameters
Usage
$identity = 'ben.edmunds@gmail.com';
$password = '12345678';
$this->ion_auth->increase_login_attempts($identity)
clear_login_attempts()
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
succeded.
Parameters
Usage
$identity = 'ben.edmunds@gmail.com';
$password = '12345678';
$this->ion_auth->clear_login_attempts($identity)
user()
Get a user.
Parameters
Return
stdClass Object (
[id] => 1
[ip_address] => 127.0.0.1
[activation_code] =>
19e181f2ccc2a7ea58a2c0aa2b69f4355e636ef4
[forgotten_password_code] =>
81dce1d0bc2c10fbdec7a87f1ff299ed7e4c9e4a
[remember_code] =>
9d029802e28cd9c768e8e62277c0df49ec65c48c
[active] => 0
Usage
$user = $this->ion_auth->user()->row();
echo $user->email;
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.
Return
array of objects
Usage
$users = $this->ion_auth->users()->result();
group()
Get a group.
Parameters
Return
object
Usage
$group_id = 2;
$group = $this->ion_auth->group($group_id);
groups()
Return
array of objects
Usage
$groups = $this->ion_auth->groups()->result();
messages()
Get messages.
Return
string
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
$messages = $this->ion_auth->messages();
echo $messages;
else
{
$errors = $this->ion_auth->errors();
echo $errors;
messages_array()
Return
array
Parameters
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
$messages = $this->ion_auth->messages_array();
echo $message;
else
$errors = $this->ion_auth->errors_array();
echo $error;
}
get_users_groups()
Parameters
Return
stdClass Object (
[id] => 1
Usage
$user_groups = $this->ion_auth->get_users_groups($user->id)->result();
add_to_group()
Add user to group
Parameters
Return
boolean. TRUE if the user was added to group(s) FALSE if the user is not
added to group(s).
Usage
$this->ion_auth->add_to_group(1, $user_id);
remove_from_group()
Parameters
1. 'Group_id' - NULL, integer or array REQUIRED. NULL will remove the user
from all groups.
Return
boolean. TRUE if the user was removed from group(s) FALSE if the user is
not removed from group(s).
Usage
$this->ion_auth->remove_from_group(1, $user_id);
$this->ion_auth->remove_from_group(NULL, $user_id);
create_group()
Create a group
Parameters
2. 'group_description' - string.
Return
brand new group_id if the group was created, FALSE if the group creation
failed.
Usage
if(!$group)
$view_errors = $this->ion_auth->messages();
else
$new_group_id = $group;
update_group()
Parameters
3. 'group_description' - string.
Return
boolean. TRUE if the group was updated, FALSE if the update failed.
Usage
$group_id = 2;
$group_name = 'test_group_changed_name';
if(!$group_update)
$view_errors = $this->ion_auth->messages();
else
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
boolean. TRUE if the group was deleted, FALSE if the delete failed.
Usage
$group_id = 2;
$group_delete = $this->ion_auth->delete_group($group_id);
if(!$group_delete)
$view_errors = $this->ion_auth->messages();
else
}
set_message_delimiters()
Parameters
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
$this->ion_auth-
>set_message_delimiters('<p><strong>','</strong></p>');
$messages = $this->ion_auth->messages();
echo $messages;
else
{
$this->ion_auth->set_error_delimiters('<p><strong>','</strong></p>');
$errors = $this->ion_auth->errors();
echo $errors;
errors()
Return
string
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
{
$messages = $this->ion_auth->messages();
echo $messages;
else
$errors = $this->ion_auth->errors();
echo $errors;
errors_array()
Return
array
Parameters
1. 'Langify' - boolean OPTIONAL. TRUE means that the error messages will be
langified.
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
$messages = $this->ion_auth->messages_array();
echo $message;
else
$errors = $this->ion_auth->errors_array();
{
echo $error;
set_error_delimiters()
Parameters
Usage
$id = 12;
$data = array(
);
if ($this->ion_auth->update_user($id, $data))
{
$this->ion_auth-
>set_message_delimiters('<p><strong>','</strong></p>');
$messages = $this->ion_auth->messages();
echo $messages;
else
$this->ion_auth->set_error_delimiters('<p><strong>','</strong></p>');
$errors = $this->ion_auth->errors();
echo $errors;
set_hook()
Parameters
Usage
parent::__construct();
/*
The following does not need to go in __construct() it just needs to be set before
you trigger_events().
*/
$event = 'socialpush';
$class = 'Accounts';
$method = 'email';
$name = 'call_Twitter';
$method = 'twitter';
$name = 'call_MailChimp_API';
$method = 'mailchimp';
$name = 'call_Facebook_API';
$method = 'facebook';
$name = 'call_gPlus_API';
$method = 'gplus';
$this->ion_auth->trigger_events('socialpush');
return true;
return true;
return true;
return true;
}
public function gplus($content, $who)
return true;
trigger_events()
Parameters
Usage
$this->ion_auth->trigger_events('socialpush');
And here's an yet another ad. These ads bring in about $50/month so it
doesn't come close to paying for the time I spend supporting Ion Auth but
every little bit does help. Thanks for visiting.
======================================
Mongo_DB
by Ben Edmunds
======================================
Yo,
This is a class for using MongoDB with CI. This is an extreme work in
progress. There are a ton of features I would like to add/change so
feel free to fork and add features.
INSTALLATION:
Just copy the files from this package to the correspoding folder in your
application folder. Then insert the appropriate settings in the config
file. You will also need MongoDB setup and working with the PECL Mongo
class.
USING MONGO_DB:
Below is sample controller code. There is also a example model
named Blog_model that will walk you through extending mongo_db
with your own models.
//this would likely be auto-loaded but you can load it when needed
as well
$this->load->model('mongo_db');
//this would likely be auto-loaded but you can load it when needed
as well
$this->load->model('mongo_db');
Feel free to send me an email or create an issue if you have any problems
but keep in mind this is extremely new...
Thanks,
-Ben Edmunds
ben.edmunds@gmail.com
@benedmunds
Ion Auth 2
The future of authentication
by Ben Edmunds
Redux Auth 2 had a lot of potential. It's lightweight, simple, and clean, but had a ton of
bugs and was missing some key features. So we refactored the code and added new
features.
This version drops any backwards compatibility and makes things even more awesome
then you could expect.
Support
If you use this to further your career, or put money in your pocket, and would like to
support the project please consider a moral license.
Documentation
Installation
Just copy the files from this package to the corresponding folder in your application folder.
For example, copy Ion_auth/config/ion_auth.php to application/config/ion_auth.php
You can also copy the libraries and models directories into your third_party/ion_auth
folder. For example, copy to /application/third_party/ion_auth/. The directory structure
would be:
controllers/Auth.php
views/
third_party/ion_auth/libraries/Ion_auth.php
third_party/ion_auth/libraries/Bcrypt.php
third_party/ion_auth/models/Ion_auth_model.php
Then in your controller add the package path and load the library like normal
$this->load->add_package_path(APPPATH.'third_party/ion_auth/');
$this->load->library('ion_auth);
Relational DB Setup
Then just run the appropriate SQL file (if you're using migrations you can get the
migrations from JD here:https://github.com/iamfiscus/codeigniter-ion-auth-migration).
Usage
In the package you will find example usage code in the controllers and views folders. The
example code isn't the most beautiful code you'll ever see but it'll show you how to use
the library and it's nice and generic so it doesn't require a MY_controller or anything else.
Default Login
Important
It is highly recommended that you use encrypted database sessions for security!
Optimization
Options
Time Based One-Time Password (TOTP) - There is a Time Based One-Time Password
(TOTP) implementation compatible with Google Authenticator available. Feature branch
maintained by biscofil and is available athttps://github.com/benedmunds/CodeIgniter-Ion-
Auth/tree/otp
1. Pada halaman upload foto, user memilih file yang akan di upload kemudian tekan tombol
submit.
2. Controller menerima action post dari form, kemudian datanya diolah, jika upload foto sesuai
dengan setup config parameter codeigniter, result true, sebaliknya false.
3. Return data berbentuk array kemudian dilempar kembali ke view, yang kemudian dapat diolah
lebih lanjut, dapat diambil nama filenya, ukuran file, tipe file dsb.
Bagaimana, sudah pahamkan konsepnya ? jika masih ada yang ingin ditanyakan silahkan
tuliskan di kotak komentar, dan berikut ini adalah tutorial lengkapnya, selamat mencoba,
link download lengkap ada di bagian bawah tutorial ini.
1 <?php
2 defined('BASEPATH') OR exit('No direct script access allowed');
3
4 class Upload extends CI_Controller {
5
6 public function index()
7 {
8 // load helper url, digunakan untuk membuat form di view
9 $this->load->helper('url');
10
11 // menampilkan view form_upload_foto.php
12 $this->load->view('form_upload_foto');
13 }
14
15
16 public function upload_foto()
17 {
18 // setup config untuk upload
19
20 // nama folder upload, tanda ./ merupakan folder root dari aplikasi
21 $config['upload_path'] = './uploads';
22
23 // format file yang di dukung, untuk menambahkan format lain tinggal |namaformat
24 $config['allowed_types'] = 'gif|jpg|png|bmp';
25
26 // memanggil library upliad
27 $this->load->library('upload', $config);
28
29 // upload foto ! dan simpan hasilnya ke variabel $upload foto
30 $upload_foto = $this->upload->do_upload('nama_file');
31
32 echo '<pre>';
33
34 // jika hasil upload error, tampilkan error
35 if($upload_foto === FALSE)
36 {
37 print_r($this->upload->display_errors());
38 }
39
40 // jika hasil benar
41 else
42 {
43 $upload_data = $this->upload->data();
44
45 //tampilkan data dalam bentuk array
46 print_r($upload_data);
47
48 // untuk mengambil nama file, caranya
49 //echo $upload_data['nama_file'];
50 }
51 }
52 }
di bawah ini adalah contoh hasil output ketika submit file foto.
1 Array
2 (
3 [file_name] => button-dari-images.png
4 [file_type] => image/png
5 [file_path] => /Applications/XAMPP/xamppfiles/htdocs/teach/ci_upload_foto/uploads/
6 [full_path] => /Applications/XAMPP/xamppfiles/htdocs/teach/ci_upload_foto/uploads/button-dari-images.png
7 [raw_name] => button-dari-images
8 [orig_name] => button-dari-images.png
9 [client_name] => button-dari-images.png
10 [file_ext] => .png
11 [file_size] => 29.79
12 [is_image] => 1
13 [image_width] => 419
14 [image_height] => 320
15 [image_type] => png
16 [image_size_str] => width="419" height="320"
17 )
Contoh, misal kita ingin mendapatkan nama file, maka cara mengambilnya di file view
adalah $file_name;