Portal Engine
Version 3.x > Portal Engine > CustomEventHandler View modes: 
User avatar
Member
Member
lordaragon@gmail.com - 9/8/2008 9:19:44 AM
   
CustomEventHandler
Hi,

I have an existing external user database which already serving a number of portals. I have created a new website and this site is planned to use the exisiting user database for user authentication.

How do I use the information stored in the existing user database such as email, username, etc and implement the CustomEventHandler without copying the information (user) to Kentico's user database (CMS_User)?

Thanks in advance.

=========
Halim Dahlan
=========

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/8/2008 9:47:44 AM
   
RE:CustomEventHandler
Hi,

could you please see these topics?

http://www.kentico.com/docs/devguide/index.html?events_overview.htm

http://www.kentico.com/docs/devguide/security_handler_customsecurit.htm

I hope, this will be helpful for you.

Best regards,
Helena Grulichova

User avatar
Member
Member
lordaragon@gmail.com - 9/8/2008 10:17:37 AM
   
RE:CustomEventHandler
Thanks for the links Helena.

I have tried that but every time a user is authenticated it will create a new user entry in CMS_User.

My objective is to authenticate user from an external user database and use all the information stored via UserInfo object without having to manage 2 different user database (the external and CMS_User).

Appreciate if you could give a sample or code snippet (besides the one in the documentation) on how to implement this.

Best Regards,
Halim Dahlan

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/9/2008 4:01:58 AM
   
RE:CustomEventHandler
Unfortunately, it is needful to use two databases and one record for each user in both of them.

You could copy the records from your external database programmatically and update them according one of them (or maybe use some external tool to synchronize the databases).

The sample code would be similar to the one from Developer’s Guide. It could look like this (logical structure):

if (userInfo != null)
{
if (userInfo.IsExternal = true)
{
If !(values of userInfo correspond to record of external database)
{
Update userInfo;
}
}
return userInfo;
}

// Sample external user credentials
UserInfo usr = null;

// Not authenticated, authenticate from the external source
if (UserName && Password correspond to any record of your external database)
{
// Create base user record if user found
usr = new UserInfo();
usr.IsExternal = true;
usr.UserName = UserName;
usr.UserPassword = Password;
usr.Enabled = true;

copy information from your external database – e.g. usr.Email, usr.FullName, ...

// Init user sites and roles if requested
Hashtable rolesTable = new Hashtable();
string siteName = CMSContext.CurrentSite.SiteName;
// Assign user to the current site
usr.SitesRoles[siteName.ToLower()] = rolesTable;
// Add new role "external role" and assign it to the user
rolesTable["external role"] = 0;
}

// Return the user info
return usr;

Best regards,
Helena Grulichova