-
Notifications
You must be signed in to change notification settings - Fork 0
FreakAuth Vanilla integration an auth lib and a forum engine
[b]SUMMARY[/b] If you use Freakuth light authentication API (FAL), you'll be able to integrate the Vanilla forum engine.
If you already use Vanilla, you won't find a way here to insert your users in FAL's tables. But we'll be glad if you explain how you managed to do so in a week or two.
[b]REQUIREMENTS[/b] This integration of Vanilla needs to dip into CI, CI 1.5.1 or 1.5.2, Freakuth light authentication API and [url=http://getvanilla.com]Vanilla[/url].
[url=http://codeigniter.com/forums/viewthread/51174/]forum thread[/url]
The following steps are based on [url=http://lussumo.com/docs/doku.php?id=vanilla:integration:wordpress]this article[/url].
[b]VANILLA INSTALL[/b] First, you will run the Vanilla installation and put all of the Vanilla tables into your existing database.
In the step 3 of the Vanilla Installation Wizard, you have to set up some administrative stuff. Since we now use FAL, this admin won't be used after integration has succeeded
WARNING: if testing with a weak local mysql account with a blank password, you'll have to be sure to have this line in [b]/conf/database.php[/b] [code] $Configuration['DATABASE_PASSWORD'] = ''; [/code]
[b]DATABASE MAPPING[/b]
In [b]/conf/database.php[/b], add this line: [code] include 'FAL_integration_database.php'; [/code]
Now create the [b]FAL_integration_database.php[/b], where we will tell Vanilla the right table and columns.
[code] // Vanilla-FreakAuth light Integration
// Map to the FAL user table $DatabaseTables['User'] = 'fa_user';
// Map existing and matching FAL columns $DatabaseColumns['User']['UserID'] = 'id'; $DatabaseColumns['User']['Name'] = 'user_name'; $DatabaseColumns['User']['Password'] = 'password'; $DatabaseColumns['User']['Email'] = 'email';
// Also map the other FAL columns $DatabaseColumns['User']['country_id'] = 'country_id'; $DatabaseColumns['User']['role'] = 'role'; $DatabaseColumns['User']['banned'] = 'banned'; $DatabaseColumns['User']['forgotten_password_code'] = 'forgotten_password_code'; $DatabaseColumns['User']['last_visit'] = 'last_visit'; $DatabaseColumns['User']['created'] = 'created'; $DatabaseColumns['User']['modified'] = 'modified'; [/code]
[b]OTHER NEEDED COLUMNS[/b]
Now you have to add all of the fields from the Vanilla User table, that your [i]fa_user[/i] table doesn't already have.
VANILLA (LUM_User) [code] +-------------------------------+---------------+------+-----+---------------------+---------------+ | Field | Type | Null | Key | Default | Extra | +-------------------------------+---------------+------+-----+---------------------+---------------+ | UserID | int(10) | | PRI | NULL | auto_increment| | RoleID | int(2) | | MUL | 0 | | | StyleID | int(3) | | MUL | 1 | | | CustomStyle | varchar(255) | YES | | NULL | | | FirstName | varchar(50) | | | | | | LastName | varchar(50) | | | | | | Name | varchar(20) | | MUL | | | | Password | varchar(32) | YES | | NULL | | | VerificationKey | varchar(50) | | | | | | EmailVerificationKey | varchar(50) | YES | | NULL | | | Email | varchar(200) | | | | | | UtilizeEmail | enum('1','0') | | | 0 | | | ShowName | enum('1','0') | | | 1 | | | Icon | varchar(255) | YES | | NULL | | | Picture | varchar(255) | YES | | NULL | | | Attributes | text | YES | | NULL | | | CountVisit | int(8) | | | 0 | | | CountDiscussions | int(8) | | | 0 | | | CountComments | int(8) | | | 0 | | | DateFirstVisit | datetime | | | 0000-00-00 00:00:00 | | | DateLastActive | datetime | | | 0000-00-00 00:00:00 | | | RemoteIp | varchar(100) | | | | | | LastDiscussionPost | datetime | YES | | NULL | | | DiscussionSpamCheck | int(11) | | | 0 | | | LastCommentPost | datetime | YES | | NULL | | | CommentSpamCheck | int(11) | | | 0 | | | UserBlocksCategories | enum('1','0') | | | 0 | | | DefaultFormatType | varchar(20) | YES | | NULL | | | Discovery | text | YES | | NULL | | | Preferences | text | YES | | NULL | | | SendNewApplicantNotifications | enum('1','0') | | | 0 | | +-------------------------------+---------------+------+-----+---------------------+---------------+ [/code]
FAL (fa_user) [code] +-------------------------+--------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------------+--------------+------+-----+---------------------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | user_name | varchar(45) | | | | | | country_id * | int(11) | YES | MUL | NULL | | | password | varchar(50) | | | | | | email | varchar(120) | | | | | | role * | varchar(50) | | | user | | | banned * | tinyint(1) | | | 0 | | | forgotten_password_code*| varchar(50) | YES | | NULL | | | last_visit * | datetime | YES | | NULL | | | created * | timestamp | YES | | CURRENT_TIMESTAMP | | | modified * | timestamp | YES | | 0000-00-00 00:00:00 | | +-------------------------+--------------+------+-----+---------------------+----------------+ [/code]
Thanks to this script:
[code] ALTER TABLE fa_user ADD RoleID int(2) NOT NULL default '3', ADD StyleID int(3) NOT NULL default '1', ADD CustomStyle varchar(255) default NULL, ADD FirstName varchar(50) NOT NULL default '', ADD LastName varchar(50) NOT NULL default '', ADD VerificationKey varchar(50) NOT NULL default '', ADD EmailVerificationKey varchar(50) default NULL, ADD UtilizeEmail enum('1','0') NOT NULL default '0', ADD ShowName enum('1','0') NOT NULL default '1', ADD Icon varchar(255) default NULL, ADD Picture varchar(255) default NULL, ADD Attributes text NULL, ADD CountVisit int(8) NOT NULL default '0', ADD CountDiscussions int(8) NOT NULL default '0', ADD CountComments int(8) NOT NULL default '0', ADD DateFirstVisit datetime NOT NULL default '0000-00-00 00:00:00', ADD DateLastActive datetime NOT NULL default '0000-00-00 00:00:00', ADD RemoteIp varchar(100) NOT NULL default '', ADD LastDiscussionPost datetime default NULL, ADD DiscussionSpamCheck int(11) NOT NULL default '0', ADD LastCommentPost datetime default NULL, ADD CommentSpamCheck int(11) NOT NULL default '0', ADD UserBlocksCategories enum('1','0') NOT NULL default '0', ADD DefaultFormatType varchar(20) default NULL, ADD Discovery text, ADD Preferences text, ADD SendNewApplicantNotifications enum('1','0') NOT NULL default '0',
ADD KEY user_role
(RoleID
),
ADD KEY user_style
(StyleID
),
ADD KEY user_name
(user_name
);
[/code]
Now you have to give to the FAL superadmin the settings of the Vanilla superadmin you just created.
[code] update fa_user set RoleID=(select RoleID from LUM_User where id=1), StyleID=(select StyleID from LUM_User where id=1), CustomStyle=(select CustomStyle from LUM_User where id=1), FirstName=(select FirstName from LUM_User where id=1), LastName=(select LastName from LUM_User where id=1), VerificationKey=(select VerificationKey from LUM_User where id=1), EmailVerificationKey=(select EmailVerificationKey from LUM_User where id=1), UtilizeEmail=(select UtilizeEmail from LUM_User where id=1), ShowName=(select ShowName from LUM_User where id=1), Icon=(select Icon from LUM_User where id=1), Picture=(select Picture from LUM_User where id=1), Attributes=(select Attributes from LUM_User where id=1), CountVisit=(select CountVisit from LUM_User where id=1), CountDiscussions=(select CountDiscussions from LUM_User where id=1), CountComments=(select CountComments from LUM_User where id=1), DateFirstVisit=(select DateFirstVisit from LUM_User where id=1), DateLastActive=(select DateLastActive from LUM_User where id=1), RemoteIp=(select RemoteIp from LUM_User where id=1), LastDiscussionPost=(select LastDiscussionPost from LUM_User where id=1), DiscussionSpamCheck=(select DiscussionSpamCheck from LUM_User where id=1), LastCommentPost=(select LastCommentPost from LUM_User where id=1), CommentSpamCheck=(select CommentSpamCheck from LUM_User where id=1), UserBlocksCategories=(select UserBlocksCategories from LUM_User where id=1), DefaultFormatType=(select DefaultFormatType from LUM_User where id=1), Discovery=(select Discovery from LUM_User where id=1), Preferences=(select Preferences from LUM_User where id=1), SendNewApplicantNotifications=(select SendNewApplicantNotifications from LUM_User where id=1) where id=1; [/code]
[b]AUTH CLASS[/b]
Eventually, you will need to write a new Authenticator class, to make Vanilla use your existing session management code.
In [b]conf/settings.php[/b], please add:
[code] // FAL integration $Configuration['AUTHENTICATION_MODULE'] = 'People/People.Class.FAL_Authenticator.php'; $Configuration['SAFE_REDIRECT'] = '../index.php/auth/'; [/code]
The file [b]People.Class.FAL_Authenticator.php[/b] must be created in [b]library/People/[/b].
[code] <?php /*
-
Copyright 2003 Mark O'Sullivan
-
This file is part of People: The Lussumo User Management System.
-
Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-
Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
The latest source code is available at www.lussumo.com
-
Contact Mark O'Sullivan at mark [at] lussumo [dot] com
-
This class replaces the original one
-
(see "AUTHENTICATION_MODULE" configuration setting)
-
the only function that has been changed: GetIdentity()
-
some others have been removed
-
author: Christophe Gragnic (grahack) 2007
-
Applications utilizing this file: Vanilla; */ class Authenticator { var $Context;
function Authenticator(&$Context) { $this->Context = &$Context; }
function GetIdentity() { // dip into Code Igniter Framework require($this->Context->Configuration['APPLICATION_PATH'].'../system/cidip/cidip_index.php'); $obj =& get_instance(); $UserID = $obj->db_session->userdata('id'); if ($UserID=='') $UserID = 0;
if (!session_id()) { session_start(); } // If it has now been found, set up the session. $this->AssignSessionUserID($UserID); return $UserID;
}
// All methods below this point are specific to this authenticator and // should not be treated as interface methods. The only required interface // properties and methods appear above.
function AssignSessionUserID($UserID) { if ($UserID > 0) { @$_SESSION[$this->Context->Configuration['SESSION_USER_IDENTIFIER']] = $UserID; } }
function LogIp($UserID) { if ($this->Context->Configuration['LOG_ALL_IPS']) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('IpHistory', 'i'); $s->AddFieldNameValue('UserID', $UserID); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); $s->AddFieldNameValue('DateLogged', MysqlDateTime());
$this->Context->Database->Insert($s, 'Authenticator', 'LogIp', 'An error occurred while logging your IP address.', false); // fail silently }
}
function SetCookieCredentials($CookieUserID, $VerificationKey) { // Note: 2592000 is 606024*30 or 30 days setcookie($this->Context->Configuration['COOKIE_USER_KEY'], $CookieUserID, time()+2592000, $this->Context->Configuration['COOKIE_PATH'], $this->Context->Configuration['COOKIE_DOMAIN']); setcookie($this->Context->Configuration['COOKIE_VERIFICATION_KEY'], $VerificationKey, time()+2592000, $this->Context->Configuration['COOKIE_PATH'], $this->Context->Configuration['COOKIE_DOMAIN']); }
function UpdateLastVisit($UserID, $VerificationKey = '') { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('User', 'u'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); if ($VerificationKey != '') $s->AddFieldNameValue('VerificationKey', $VerificationKey); $s->AddFieldNameValue('CountVisit', 'CountVisit + 1', 0); $s->AddWhere('u', 'UserID', '', $UserID, '=');
$this->Context->Database->Update($s, 'Authenticator', 'UpdateLastVisit', 'An error occurred while updating your profile.', false); // fail silently
} } ?> [/code]
[b]VISUAL STUFF[/b]
Do as the Vanilla docs suggest:
[b]1)[/b] Copy the “Vanilla” folder within the root “themes” folder and paste it with your new name, like [b]themes/your_new_theme_name[/b]. Once this is complete, you have a skeleton of the folder structure, images, and css required for a theme.
[b]2)[/b] Copy the template file(s) you want to change into this new directory. Then change the file(s) as much as you want. Only copy the template files you need to alter.
[b]note[/b]: since [b]People.Class.FAL_Authenticator.php[/b] doesn't provide every function, you'll have to hide some links or buttons (like in menu.php, see below).
[b]3)[/b] Finally, change the css and image files in the styles/default folder as necessary to work with your new templates.
What I personnaly did:
- override [b]menu.php[/b] (removed the and used '<?php $obj =& get_instance();echo $obj->load->view('my_menu', null, true); ?>' to catch the menu I use everywhere on my site)
- override [b]head.php[/b] (hardcoded the css link because of a unexplained bug, change path to favicon.ico)
- override [b]foot.php[/b] (added my footer with the same trick than for the menu)
[b]WHAT'S NEXT[/b]
Merging FAL and Vanilla accounts of existing installations is another story...
[b]Discussions[/b]
[url=http://codeigniter.com/forums/viewthread/63771/]63771[/url]