public ActionResult HandleRegisterHostForm(RegisterHostForm registerHostForm) { if (!this.ModelState.IsValid) { return(this.CurrentUmbracoPage()); } // no helper method on this.Members to register a user with a given memberType, so calling provider directly UmbracoMembershipProviderBase membersUmbracoMembershipProvider = (UmbracoMembershipProviderBase)Membership.Providers[Constants.Conventions.Member.UmbracoMemberProviderName]; MembershipCreateStatus membershipCreateStatus; MembershipUser membershipUser = membersUmbracoMembershipProvider.CreateUser( PartyHost.Alias, // member type alias registerHostForm.EmailAddress, // username registerHostForm.Password, // password registerHostForm.EmailAddress, // email null, // forgotten password question null, // forgotten password answer true, // is approved null, // provider user key out membershipCreateStatus); if (membershipCreateStatus != MembershipCreateStatus.Success) { switch (membershipCreateStatus) { case MembershipCreateStatus.DuplicateEmail: case MembershipCreateStatus.DuplicateUserName: this.ModelState.AddModelError("RegisterHostValidation", "Email already registered"); break; } return(this.CurrentUmbracoPage()); } // cast from MembershipUser rather than use this.Members.GetCurrentMember() helper (which needs a round trip for the login) PartyHost partyHost = (PartyHost)membershipUser; partyHost.FacebookRegistration = false; partyHost.MarketingSource = registerHostForm.MarketingSource; Guid partyGuid = Guid.NewGuid(); this.DatabaseContext.Database.Insert(new PartyRow(partyGuid)); // update database with member and party guid (duplicated data, but never changes) this.DatabaseContext.Database.Insert(new MemberPartyRow(partyHost.Id, partyGuid)); // (duplicate data) store party guid in cms cache partyHost.PartyGuid = partyGuid; // set the default custom url to be the party guid partyHost.PartyUrlIdentifier = partyGuid.ToString(); // set default party date partyHost.PartyDateTime = PartyHost.DefaultPartyDate; // add member to DotMailer DotMailerService.HostRegistrationStarted((Contact)partyHost); // send cookie FormsAuthentication.SetAuthCookie(partyHost.Username, true); // cause redirect, so that the login takes effect return(this.RedirectToCurrentUmbracoPage()); }
public FormResponse RegisterHost([FromBody] FacebookCredentials facebookCredentials) { FormResponse formResponse = new FormResponse(); // using the supplied credentials query facebook to get email and names FacebookDetails facebookDetails = this.GetFacebookDetails(facebookCredentials); // no helper method on this.Members to register a user with a given memberType, so calling provider directly UmbracoMembershipProviderBase membersUmbracoMembershipProvider = (UmbracoMembershipProviderBase)Membership.Providers[Constants.Conventions.Member.UmbracoMemberProviderName]; MembershipCreateStatus membershipCreateStatus; MembershipUser membershipUser = membersUmbracoMembershipProvider.CreateUser( PartyHost.Alias, // member type alias facebookDetails.EmailAddress, // username this.GetPassword(facebookDetails), // password facebookDetails.EmailAddress, // email null, // forgotten password question null, // forgotten password answer true, // is approved null, // provider user key out membershipCreateStatus); if (membershipCreateStatus != MembershipCreateStatus.Success) { switch (membershipCreateStatus) { case MembershipCreateStatus.DuplicateEmail: case MembershipCreateStatus.DuplicateUserName: this.ModelState.AddModelError("RegisterHostValidation", "Email already registered"); formResponse.Errors = this.ModelState.GetErrors(); break; } return(formResponse); } // cast from MembershipUser rather than use this.Members.GetCurrentMember() helper (which needs a round trip for the login) PartyHost partyHost = (PartyHost)membershipUser; partyHost.FacebookRegistration = true; partyHost.FirstName = facebookDetails.FirstName; partyHost.LastName = facebookDetails.LastName; Guid partyGuid = Guid.NewGuid(); this.DatabaseContext.Database.Insert(new PartyRow(partyGuid)); // update database with member and party guid (duplicated data, but never changes) this.DatabaseContext.Database.Insert(new MemberPartyRow(partyHost.Id, partyGuid)); // (duplicate data) store party guid in cms cache partyHost.PartyGuid = partyGuid; // set the default custom url to be the party guid partyHost.PartyUrlIdentifier = partyGuid.ToString(); // set default party date partyHost.PartyDateTime = PartyHost.DefaultPartyDate; // add member to DotMailer DotMailerService.HostRegistrationStarted((Contact)partyHost); // send cookie FormsAuthentication.SetAuthCookie(partyHost.Username, true); formResponse.Success = true; formResponse.Message = this.Umbraco.TypedContentSingleAtXPath("//" + Wonderland.Logic.Models.Content.RegisterHost.Alias).Url; return(formResponse); }