ASPX templates
Version 4.x > ASPX templates > Problem with second and subsquenet logins via CustomSecurityHandler View modes: 
User avatar
Member
Member
mario-menti - 8/12/2009 3:56:30 AM
   
Problem with second and subsquenet logins via CustomSecurityHandler
Hi there,

I'm using the OnAuthentication event in the CustomSecurityHandler to authenticate users against an existing user database. The first time a user logs in it seems to work ok, and a corresponding Kentico user is created. However, if that existing user logs in again, I get this error:

[DataConnection.ExecuteQuery]: Query: UPDATE CMS_User SET [UserName] = @UserName, [FirstName] = @FirstName, [MiddleName] = @MiddleName, [LastName] = @LastName, [FullName] = @FullName, [Email] = @Email, [UserPassword] = @UserPassword, [PreferredCultureCode] = @PreferredCultureCode, [PreferredUICultureCode] = @PreferredUICultureCode, [UserEnabled] = @UserEnabled, [UserIsEditor] = @UserIsEditor, [UserIsGlobalAdministrator] = @UserIsGlobalAdministrator, [UserIsExternal] = @UserIsExternal, [UserPasswordFormat] = @UserPasswordFormat, [UserCreated] = @UserCreated, [LastLogon] = @LastLogon, [UserStartingAliasPath] = @UserStartingAliasPath, [UserGUID] = @UserGUID, [UserLastModified] = @UserLastModified, [UserLastLogonInfo] = @UserLastLogonInfo, [UserIsHidden] = @UserIsHidden, [UserVisibility] = @UserVisibility WHERE [UserID] = @UserID: caused exception: The UPDATE statement conflicted with the REFERENCE constraint "FK_CMS_UserSettings_CMS_User". The conflict occurred in database "KenticoCMS", table "dbo.CMS_UserSettings", column 'UserSettingsUserGUID'.

I'm using something very similar to the example in the documentation, just (obviously) hooked up to a db:

usr = new UserInfo();
usr.IsExternal = true;
usr.UserName = myReader["EMail"].ToString();
usr.Email = myReader["EMail"].ToString();
usr.FirstName = myReader["FirstName"].ToString();
usr.LastName = myReader["LastName"].ToString();
usr.FullName = myReader["FirstName"].ToString() + " " + myReader["LastName"].ToString();
usr.Enabled = true;

// 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;

Is there anything I need to do to handle the above excpeption, and if so what?

Cheers,
Mario.

User avatar
Member
Member
mario-menti - 8/12/2009 5:28:01 AM
   
RE:Problem with second and subsquenet logins via CustomSecurityHandler
UPDATE: I just heard back from Kentico support, and they say this is a bug in the current version. The workaround, which appears to fix the issue, is to add the below:

UserInfo existingUser = UserInfoProvider.GetUserInfo(username);
if (existingUser != null)
{
usr.UserGUID = existingUser.UserGUID;
usr.UserSettings.UserSettingsID = existingUser.UserSettings.UserSettingsID;
}

Thought I'd update the thread for the record, if anyone else has the same issue.