Alright, I have a custom Authentication Provider that I've been working on. On login, it connects to a UNIX server and authenticates the user. Then if that is successful, it checks the Users table for the same user, updates some info from a custom table and Logs them in if they exist. If they don't exist in the Users table, it creates them using info from a custom table.
Here's my code:
//Get your information from the external database
try
{
{
dealerNumber = response.Substring(response.IndexOf(
}
{
WebClient webClient = new WebClient();Stream webResponse = webClient.OpenRead(_AuthenticationWebURL+enteredUsername+"~"+enteredPassword);StreamReader reader = new StreamReader(webResponse);string response = reader.ReadToEnd();string dealerNumber = string.Empty;if (response.Length > 10)"<title>")+7,5);if (dealerNumber != "00000")KochAirDealersController objDCtrl = new KochAirDealersController();KochAirDealersInfo objDealer = objDCtrl.Get(Convert.ToInt32(dealerNumber));KochAirUsersController objUCtrl = new KochAirUsersController();KochAirUsersInfo objUser = objUCtrl.GetByUserName(enteredUsername);//Determine if we have the user
{
dnnUser.PortalID = _portalSettings.PortalId;
dnnUser.Username = enteredUsername;
dnnUser.FirstName = dnnUser.Profile.FirstName = objUser.FirstName;
dnnUser.LastName = dnnUser.Profile.LastName = objUser.LastName;
dnnUser.Email = objUser.Email;
if (dnnUser != null)//oUser.Profile.ProfileProperties["DealerNumber"] = objDealer.DealerId.ToString();
//oUser.Profile.ProfileProperties["DealerName"] = objDealer.Name;
//oUser.Profile.ProfileProperties["DealerLine"] = objDealer.Line;
//oUser.Profile.ProfileProperties["DealerLocation"] = objDealer.LocationId;
dnnUser.IsSuperUser =
dnnUser.Membership.Username = enteredUsername;
dnnUser.Membership.Password = enteredPassword;
dnnUser.Membership.Email = objUser.Email;
dnnUser.Membership.Approved =
dnnUser.Membership.LastLoginDate =
false;true;DateTime.Now;UserController.UpdateUser(this.PortalId, dnnUser);//Log the user in!
RaiseAuthenticationEvent(dnnUser, enteredUsername,
}
UserLoginStatus.LOGIN_SUCCESS, true, "");else
{
//Response.Redirect(objUser.FirstName);
//Add user into the system
dnnUser =
dnnUser.PortalID =
dnnUser.IsSuperUser =
dnnUser.FirstName = objUser.FirstName;
dnnUser.LastName = objUser.LastName;
dnnUser.Email = objUser.Email;
dnnUser.Username = enteredUsername;
dnnUser.DisplayName =
new UserInfo();this.PortalId;false;String.Concat(objUser.FirstName, " ", objUser.LastName);//Set Membership
DotNetNuke.Entities.Users.
oNewMembership.Approved =
oNewMembership.CreatedDate = System.
oNewMembership.Email = objUser.Email;
oNewMembership.IsOnLine =
oNewMembership.Username = enteredUsername;
oNewMembership.Password = enteredPassword;
UserMembership oNewMembership = new DotNetNuke.Entities.Users.UserMembership();true;DateTime.Now;false;//Bind membership to user
dnnUser.Membership = oNewMembership;
//Add the user, ensure it was successful
{
if (UserCreateStatus.Success == UserController.CreateUser(ref dnnUser))//Log them in
RaiseAuthenticationEvent(dnnUser, enteredUsername,
}
UserLoginStatus.LOGIN_SUCCESS, true, "");else
{
DotNetNuke.Services.Exceptions.
}
}
}
Exceptions.ProcessModuleLoadException(this, new Exception("Unable to create user"));else
{
//Not valid User
RaiseAuthenticationEvent(
}
}
{
DotNetNuke.Services.Exceptions.
}
My problem is that it works perfectly is the user already exists in the Users table. It authenticates, updates and then logs them in. BUT, if the user is't in the Users table, it won
t create them. Just gives me the exception. I don't understand. I have went line by line in debug and each value is beig set, everything works perfectly until it hits the "if (UserCreateStatus.Success == UserController.CreateUser(ref dnnUser))." then it just skips the creation and moves onto the exception.
Can anyone give me some insight to what I have done wrong here??? I have been looking for 8 hrs now and still nothing.
Any help is greatly appreciated!
new UserInfo(), enteredUsername, UserLoginStatus.LOGIN_FAILURE, false, Localization.GetString("InvalidLogin", this.LocalResourceFile));catch (Exception ex)Exceptions.ProcessModuleLoadException(this, ex);