/// <summary>
        /// using the details requested from facebook, generate a password for this user (requires consistant email address + facebook userId)
        /// </summary>
        /// <param name="facebookDetails"></param>
        /// <returns></returns>
        private string GetPassword(FacebookDetails facebookDetails)
        {
            string salt = FormsAuthentication.HashPasswordForStoringInConfigFile(facebookDetails.EmailAddress.ToLower() + "70E5B25D-8A18-4302-AE04-79CBD3FC1EE0", "MD5");

            string password = FormsAuthentication.HashPasswordForStoringInConfigFile(facebookDetails.UserId + salt, "SHA1");

            return(password);
        }
        public FormResponse Login([FromBody] FacebookCredentials facebookCredentials)
        {
            FormResponse formResponse = new FormResponse();

            FacebookDetails facebookDetails = this.GetFacebookDetails(facebookCredentials);

            if (this.Members.Login(facebookDetails.EmailAddress, this.GetPassword(facebookDetails)))
            {
                formResponse.Success = true;

                formResponse.Message = ((IPartier)this.Members.GetByUsername(facebookDetails.EmailAddress)).PartyUrl;
            }
            else
            {
                this.ModelState.AddModelError("LoginValidation", "Unknown user");

                formResponse.Errors = this.ModelState.GetErrors();
            }

            return(formResponse);
        }
        public FormResponse RegisterGuest([FromUri] Guid partyGuid, [FromBody] FacebookCredentials facebookCredentials)
        {
            FormResponse formResponse = new FormResponse();

            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(
                PartyGuest.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("RegisterGuestValidation", "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)
            PartyGuest partyGuest = (PartyGuest)membershipUser;

            partyGuest.FacebookRegistration = true;

            partyGuest.FirstName = facebookDetails.FirstName;
            partyGuest.LastName  = facebookDetails.LastName;

            // update database with member and party guid (duplicated data, but never changes)
            this.DatabaseContext.Database.Insert(new MemberPartyRow(partyGuest.Id, partyGuid));

            // (duplicate data) store party guid in cms cache
            partyGuest.PartyGuid = partyGuid;

            // add member to DotMailer
            DotMailerService.GuestRegistrationStarted((Contact)partyGuest);

            // send cookie
            FormsAuthentication.SetAuthCookie(partyGuest.Username, true);

            formResponse.Success = true;

            formResponse.Message = this.Umbraco.TypedContentSingleAtXPath("//" + Wonderland.Logic.Models.Content.RegisterGuest.Alias).Url;

            return(formResponse);
        }