protected Personify.WebControls.Base.Business.PersonifyIdentity GetPersonifyUser() { //if (this.Page is PageBuilderViewer) //{ // Personify.WebControls.Base.Business.PersonifyIdentity pageUser = (this.Page as PageBuilderViewer).PersonifyUser; // if (pageUser != null) // { // return pageUser; // } //} var user = new Personify.WebControls.Base.Business.PersonifyIdentity { ContainerName = "Kentico", CurrencyCode = "USD", SubCustomerId = 0 }; // var userApi = new Ektron.Cms.UserAPI(); // if (userApi.IsLoggedIn && !userApi.IsAdmin()) // if (!string.IsNullOrEmpty(MembershipContext.AuthenticatedUser.FirstName)) if (CMS.Membership.AuthenticationHelper.IsAuthenticated()) { if (HttpContext.Current.Session["PersonifyToken"] != null) { HttpContext.Current.Session["PersonifyToken"] = ValidateCustomerToken(HttpContext.Current.Session["PersonifyToken"].ToString()); if (!string.IsNullOrEmpty(HttpContext.Current.Session["PersonifyToken"] as string)) { //Ektron.Cms.UserData ud = _ektronUserApi.GetUser(userApi.UserId); UserInfo ud = UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserID); // string cRemoteid = ConfigurationManager.AppSettings["EktronCustomProperty_MasterCustomerId"]; if (HttpContext.Current.Session["userClass"] != null) { userinfo ui = (userinfo)HttpContext.Current.Session["userClass"]; if (ui != null) { user.CustomerName = MembershipContext.AuthenticatedUser.FirstName + " " + MembershipContext.AuthenticatedUser.LastName; user.MasterCustomerId = ui.ID; //"RemoteID";//ud.CustomProperties[cRemoteid].Value.ToString(); ; user.IsLoggedIn = true; user.ShoppingGUID = ui.ID; user.MasterCustomerId = ui.ID; } } // if (ud.CustomProperties[cRemoteid] != null) { //user.IsMember = false; } } } } ///pass dummy credentials if not logged in if (string.IsNullOrEmpty(user.MasterCustomerId)) { //return dummy user user.CustomerName = "Steven Karl"; user.IsMember = false; user.IsLoggedIn = false; user.MasterCustomerId = "01786850"; } if (CMS.Membership.AuthenticationHelper.IsAuthenticated()) { bool flagadmin = false; UserInfo userdata = CMS.Membership.UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserName); DataTable dt = UserInfoProvider.GetUserRoles(userdata); if (dt.Rows.Count > 0 && dt != null) { foreach (DataRow dr in dt.Rows) { if (dr["RoleName"].ToString().ToLower().Contains("administrator")) { flagadmin = true; } } } if (flagadmin) { user.IsAdministrator = true; } else { var ck = HttpContext.Current.Request.Cookies[PersonifyControlBase.PersonifyShoppingCartGuidCookieName]; if (ck != null && ck.Value != null) { user.ShoppingGUID = ck.Value; } else { var cookieValue = HttpContext.Current.Session.SessionID; DateTime dtExpire = DateTime.Now.AddDays(CookieDurationDays); var myCookie = new HttpCookie(PersonifyControlBase.PersonifyShoppingCartGuidCookieName) { Value = cookieValue, Expires = dtExpire }; HttpContext.Current.Response.Cookies.Add(myCookie); user.ShoppingGUID = cookieValue; } } PageViewer p = new PageViewer(); p.PersonifyUser = user; } return(user); }
//This method uses the msterCustomerID (remoteID) and looks up the coresponding UserID value in the database for this user. //This is done because looking up user by UserName will not work when the username is updated in AMS (Personify). //This method returns the UserId in Ektron based on RemoteID/CustomerID from Personify. private string AuthenticateCustomer(string customerIdentifier, string email, string userName) { string sMasterCustomerId = ""; string pfirstname = ""; string plastname = ""; int subCustomerId = 0; string groupslist = ""; try { var aIdentifiers = customerIdentifier.Split('|'); sMasterCustomerId = aIdentifiers[0]; subCustomerId = int.Parse(aIdentifiers[1]); //*******Custom Dataservice code to get Firstname, Lastname*****// var personifyuser = new Personify.WebControls.Base.Business.PersonifyIdentity { ContainerName = "Kentico", CurrencyCode = "USD", MasterCustomerId = sMasterCustomerId, SubCustomerId = subCustomerId }; // var userdetails = new DemographicProvider().GetCusNameDemographic(personifyuser); // Uri ServiceUri = new Uri("http://smemi.personifycloud.com/PersonifyDataServices/PersonifyDatasme.svc"); Uri ServiceUri = new Uri(svcUri_Base); LoginUsertokentico.WriteError("AuthenticateCustomer ID ==>", sMasterCustomerId.ToString()); PersonifyEntitiesBase DataAccessLayer = new PersonifyEntitiesBase(ServiceUri); // DataAccessLayer.Credentials = new NetworkCredential("admin", "admin123"); DataAccessLayer.Credentials = new NetworkCredential(svcLogin, svcPassword); // var userdetails = DataAccessLayer.CusNameDemographics.Where(p => p.MasterCustomerId == sMasterCustomerId).Select(o => o).ToList().FirstOrDefault(); var userdetails = DataAccessLayer.CusNameDemographics.Where(p => p.MasterCustomerId == sMasterCustomerId) .Select(o => o) .ToList() .FirstOrDefault(); // var userdetails = new DemographicProvider().GetCusNameDemographic(personifyuser); pfirstname = null; plastname = null; if (userdetails == null) { pfirstname = @" "; plastname = @" "; } if (userdetails != null && string.IsNullOrWhiteSpace(userdetails.FirstName)) { pfirstname = @" "; } else { if (userdetails != null) { pfirstname = userdetails.FirstName; } } if (userdetails != null && string.IsNullOrWhiteSpace(userdetails.LastName)) { plastname = @" "; } else { if (userdetails != null) { plastname = userdetails.LastName; } } //*******End Custom Dataservice code to get Firstname, Lastname***********// string[] memberGroups = GetImsroles(sMasterCustomerId, subCustomerId); if (memberGroups.Length > 0) { foreach (string s in memberGroups) { if (s.Length > 0) { groupslist += s + ","; } } } groupslist += "peronifyUser" + ","; string login = objKenticoService.CreateUpdateLoginUserinKentico( userName, pfirstname, plastname, email, groupslist, true, false); userinfo uInfo = new userinfo { ID = sMasterCustomerId, Token = Session["PersonifyToken"].ToString(), email = email, firstname = pfirstname, lastname = plastname, username = userName, groupNames = groupslist }; Session["userClass"] = uInfo; return(login); } catch (Exception exception) { EventLogProvider.LogException("AuthenticateCustomer", "Get", exception); LoginUsertokentico.WriteError("AuthenticateCustomer", exception.ToString()); return(null); // evp.LogEvent("Source", "EventCode", exception,1); //evp.LogEvent("AuthenticateCustomer", "Get", exception.ToString(),"","",0,"",0,"","",0,"","","",DateTime.Now); } }