Try our conversational search powered by Generative AI!

Set up subscription for anonymous users

Vote:
 
Hi. Anyone tried to set up subscription for anonymous users? I understand you have to: 1. Get the email address from the current guest user (from a Form) 2. Check if this email already has been saved as an episerver user (username) 3. If so, update the account with the new settings, else create the user with the specified email address 4. Set the specified subscription settings from the form on the updated/created user Anyone got any good code examples on this? Thanks. Frank :)
#12128
Sep 16, 2004 9:41
Vote:
 
You need to use the UserSid class. Check out this the SDK and this faq for more info: http://www.episerver.com/templates/faq____976.aspx Log in the user you have created and then use the SubscribeTo(...) method to add subscriptions. To log in a user you need to do something like this: IPrincipal iPrincipal = AuthenticationProvider.Authenticate(this, name, pass); if (iPrincipal == null) return null; FormsAuthentication.Initialize(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, name, DateTime.Now, DateTime.Now.AddMinutes(5), false, pass, FormsAuthentication.FormsCookiePath ); string cookiestr = FormsAuthentication.Encrypt(ticket); string url = FormsAuthentication.GetRedirectUrl( name, false ); Response.Cookies[FormsAuthentication.FormsCookieName].Value = cookiestr;
#13709
Jan 21, 2005 9:23
Vote:
 
Thanks. I ended up with another approach when I did this earlier, and would like to post this here. In Subscribe.aspx, I use two different user controls. In page_load in the .aspx I check if the current user not is anonymous. If so, I load SubscribeAuth.ascx, which is identical the one on the Sample Site. If not, I load SubscribeAnonym.ascx. This control does the following: protected void Save_Click(object sender, EventArgs e) { if(ValidEmail()) { UnifiedPrincipal originalUser = PageBase.CurrentUser; int intInterval = Int32.Parse(Interval.SelectedItem.Value); PersonalizedData user = HandleUser(); if(user != null) { SubscriptionInfo subscriptionInfo = new SubscriptionInfo(user); //Set interval subscriptionInfo.Interval = intInterval; //Loop through list of subscription alternatives, and //add or remove from user foreach (ListItem subitem in cblSubList.Items) { if (subitem.Selected == true) subscriptionInfo.SubscribeTo(PageReference.Parse(subitem.Value), CurrentPage.LanguageID); else subscriptionInfo.UnSubscribe(PageReference.Parse(subitem.Value), CurrentPage.LanguageID); } //Save the new data on the user user.Save(); } //Show receipt SubscribeArea.Visible = false; ReceiptArea.Visible = true; //Reset CurrentUser object PageBase.CurrentUser = originalUser; } } The HandleUser method looks like this: private PersonalizedData HandleUser() { string strUserName = Email.Text; //Return if email field is blank if(strUserName == string.Empty) return null; //If user already exists, retrieve this one PersonalizedData existinguser = PersonalizedData.Load(strUserName); //Return existing user if(existinguser != null) { //Update the user's email address existinguser.Email = strUserName; return existinguser; } //Create new user else { UserSid newuser = new UserSid(SecurityIdentityType.ExtranetUser); //Add the user to the default Group int defaultGroupID = (int)Configuration["EPnDefaultGroup"]; GroupSid defaultGroup = GroupSid.LoadGroup(defaultGroupID); if(defaultGroup != null) newuser.MemberOfGroups.Add(defaultGroup); //Set the user to active newuser.Active = true; //Set user properties newuser.Name = strUserName; newuser.Email = strUserName; try { newuser.Save(); return PersonalizedData.Load(newuser.Name); } catch(DataAbstractionException error) { //ErrorOccured(error.Message); return null; } } } A bit more code, but the user doesn't get logged in with cookies and so forth, which wasn't supposed to happen in our solution. Frank :)
#13710
Jan 21, 2005 15:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.