Javascript quiz Thursday! Be sure to have Part 1 done by then!
Authentication Packages with in Fuel: SimpleAuth, OrmAuth
Contains drivers that handle users, groups, roles, and permissions
Similar to SimpleAuth, but uses a database to store all its data
Allows for direct assignment of permissions to users/groups and other features to provide a more "fine-grained permission system".
I recommend you download this template site to understand how to set up Ormauth. Later, you can then incorporate it into your own Fuel site!
Here are the files for this example
To set up OrmAuth, we need to run a couple of terminal commands using "oil", a utility that comes with Fuel... but can't be installed without valid permission.
We'll do something a bit "hacky" to set up everything
Find and copy these files: /fuel/packages/auth/config/auth.php
and /fuel/packages/auth/config/ormauth.php
; to your main /fuel/app/config/
folder.
Change the "driver" option in /fuel/app/config/auth.php
on line 25 from Simpleauth
to Ormauth
(case-sensitive!). For now, change your "salt" option to an empty string.
In /fuel/app/config/config.php
, we'll need to uncomment parts of the "always_load" section.
The lines that need to be uncommented are 262, 275-278, and 314. It should look similar to what is below:
. . . /**************************************************************************/ /* Always Load */ /**************************************************************************/ 'always_load' => array( <----262 /** * These packages are loaded on Fuel's startup. * You can specify them in the following manner: * * array('auth'); // This will assume the packages are in PKGPATH * * // Use this format to specify the path to the package explicitly * array( * array('auth' => PKGPATH.'auth/') * ); */ 'packages' => array( <----275 'orm', 'auth', ), /** * These modules are always loaded on Fuel's startup. You can specify them * in the following manner: . . . ), <----314
PHP versions prior to 5.6 don't have the "hash_equals" function, so we'll add one into the /fuel/core/classes/crypt.php
file. Add the following code around line 370.
if(!function_exists('hash_equals')) { function hash_equals($str1, $str2) { if(strlen($str1) != strlen($str2)) { return false; } else { $res = $str1 ^ $str2; $ret = 0; for($i = strlen($res) - 1; $i >= 0; $i--) { $ret |= ord($res[$i]); } return !$ret; } } }
First things first, change you fuel/app/config/development/db.php
to have your database credentials
Download this file: Create-Tables queries
This file contains all the queries for the tables OrmAuth assumes already exist
Create an action called "action_createtables" in one of your main controllers
Copy the contents of the above file and paste it inside the new action
Navigate to the corresponding webpage by typing in the action's URL to run the PHP code and create your tables. You should see a map printed out onto a white webpage.
If for some reason your action fails to create the tables properly, use this Drop-Tables queries file to clean up your database and start again.
Ormauth, and its tables, have now been added!
Copy the code from the actions
file and add it to your Fuel page.
Add the files in the view
folder to your own
Once you've followed these steps, navigate to your "register" page and create a user.
Take a look at my working basic hospital example!
It now requires for a user to sign in before viewing any other pages