NipIgniter User Guide Version 2.0


Authentication

Saya menyertakan fitur authentication sederhana pada NipIgniter. Anda dapat menggunakannya jika mau.

How to use

You need to add a field role_id and status_id in your user table. Role starting from the number 1 and so on.

Role
1 : Admin
2 : Member
3 : dst...

Authentication is used based on the controller and role_id. You must define which method that will be allowed for each role. Please look at this example below.
Asterisks(*) mean that the admin role can access any function. But, the member role only can access "someFunction" and "fooBar" function. The member still can access "index" function. Because the "index" has defined for all role.

class SiteController extends Nip_Controller{
	/**
	 * Action rules for user
	 *
	 * @var mix
	 * @access public
	 */
	protected $rules = array(
		'*' => array("index"), 				//all user can access "index"
		'1' => array("*"),  					//admin can access all function ("index", "someFunction", "fooBar", "adminPage")
		'2' => array("someFunction", "fooBar") 	//member can access "index", "someFunction" and "fooBar". But member can't access "adminPage" 
	);	

	public function index(){

		echo "index page";
	}

	public function someFunction(){

		echo "someFunction page";
	}

	public function fooBar(){

		echo "fooBar page";
	}

	public function adminPage(){

		echo "adminPage";
	}
}

Status is used to determine user status if it's activa or not when login. You can modify it in the AuthController.php

Status
1 : Active
2 : Non Active
application/controllers/AuthController.php

/**
 * Check the user table with username
 */
$loginWithUsername = $this->Auth->login(array(
							'username' => $userkey,
							'password' => $encPassword,
							'status_id'=> 1
						)
					);

Disable it

You can turn off the $authStatus in the application/core/Nip_Controller.php

/**
 * Activated the _remap() function for login
 *
 * @var string
 * @access protected
 */
protected $authStatus = FALSE;