public ActionResult HandleSignUp(CombinedRegisterLoginModel model)
        {
            // Model validation
            if (!ModelState.IsValid) return this.CurrentUmbracoPage();

            var registerModel = Members.CreateRegistrationModel(model.Registration.MemberTypeName.DecryptWithMachineKey());
            registerModel.Name = model.Registration.EmailAddress;
            registerModel.Email = model.Registration.EmailAddress;
            registerModel.Password = model.Registration.Password;
            registerModel.Username = model.Registration.EmailAddress;
            registerModel.CreatePersistentLoginCookie = model.Registration.PersistLogin;
            registerModel.UsernameIsEmail = true;

            if (registerModel.MemberProperties.Exists(x => x.Alias == "firstName"))
                registerModel.MemberProperties.Find(x => x.Alias == "firstName").Value = model.Registration.FirstName;

            if (registerModel.MemberProperties.Exists(x => x.Alias == "lastName"))
                registerModel.MemberProperties.Find(x => x.Alias == "lastName").Value = model.Registration.LastName;

            MembershipCreateStatus status;
            var membershipUser = Members.RegisterMember(registerModel, out status);

            switch (status)
            {
                case MembershipCreateStatus.InvalidPassword:
                    ModelState.AddModelError("HandleSignUpError", "Invalid password");
                    return this.CurrentUmbracoPage();

                case MembershipCreateStatus.DuplicateEmail:
                    ModelState.AddModelError("HandleSignUpError", "The email address " + model.Registration.EmailAddress + " is already associated with a customer.");
                    return this.CurrentUmbracoPage();

                case MembershipCreateStatus.DuplicateUserName:
                    ModelState.AddModelError("HandleSignUpError", "The email address " + model.Registration.EmailAddress + " is already associated with a customer.");
                    return this.CurrentUmbracoPage();

                default:
                    // TODO should not need to do this but need to ask for a better event in Umbraco
                    // but have to resave to fire off the memberservice event to populate the Merchello customer
                    // correctly
                    var member = Services.MemberService.GetByEmail(model.Registration.EmailAddress);
                    if (member != null)
                    {
                        Services.MemberService.Save(member);
                        Services.MemberService.AssignRole(member.Id, "MerchelloCustomers");
                        
                             var stringResult = SendEmailRegisterMember(model);
                        ModelState.AddModelError("HandleSignUpError", stringResult);
                    }

                    break;
            }

            return RedirectToUmbracoPage(model.AccountPageId);
        }
        public ActionResult HandleSignIn(CombinedRegisterLoginModel model)
        {
            if (!ModelState.IsValid) return this.CurrentUmbracoPage();

            if (Members.Login(model.Login.Username, model.Login.Password))
            {
                // successful login
                return this.RedirectToUmbracoPage(model.AccountPageId);
            }

            // unsuccessful login
            return this.CurrentUmbracoPage();
        }
        public string SendEmailRegisterMember(CombinedRegisterLoginModel model)
        {
            string result = "";
            try
            {
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                message.To.Add(model.Registration.EmailAddress);
                message.Subject = "Account Registration confirm";
                message.From = new System.Net.Mail.MailAddress("*****@*****.**");
                message.Body = string.Format("Hi {0}, <br/> registration confirmed. login {1} - password {2} .<br/>Thanks.", model.Registration.FirstName, model.Registration.EmailAddress, model.Registration.Password);
                message.IsBodyHtml = true;
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Send(message);
                result = "Ok. Sent to " + model.Registration.EmailAddress;
            }
            catch (Exception ex)
            {
                result = "Error: " + ex.Message;
            }

            return result;

        }