Hi there,
I am working on a site where we need users to log in with their e-mail address. So, we store the e-mail address in the AccessUserUserName field and all is good.
But I run into problems when I allow users to change their e-mail address as I also needs to change their user name. So, when changing the user data, I do something like this:
1. Run custom code to update the AccessUser table
2. Run custom code to update the EcomOrders table
I run both in a transaction to make sure they either commit all, or not at all.
Then I need to change the user's details stored in session state. I found about 714 references to the user's name and e-mail address, giving me the following horrible, horrible code:
// Fix Sessions
var session = HttpContext.Current.Session;
session["DW_extranet_username"] = newEmailAddress;
session["DW_extranet_AccessUserUserName"] = newEmailAddress;
session["DW_extranet_username"] = newEmailAddress;
session["DW_extranet_AccessUserEmail"] = newEmailAddress;
var sessionUser = HttpContext.Current.Session["UserManagement.User.Current.Frontend"] as Dynamicweb.Modules.UserManagement.User;
if (sessionUser != null)
{
sessionUser.Email = newEmailAddress;
sessionUser.UserName = newEmailAddress;
}
Dynamicweb.Login myLogin = new Dynamicweb.Login(newEmailAddress, accessUser.AccessUserPassword);
myLogin.Autologin = true;
myLogin.Login();
Is there a better way to accomplish this? Can I refresh / relogin the current user?
I try stuff like StartLogin but it redirects me and I can't have that happen....
Imar