Try our conversational search powered by Generative AI!
AI OnAI Off
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;
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 :)