public ActionResult HandleForgotPassword(ForumForgotPasswordModel model)
        {
            TempData["ResetSent"] = false;
            if (!ModelState.IsValid)
            {
                return(PartialView(Umbraco.GetDictionaryValue("ForumAuthConstants.ForgotPasswordView", "Member/ForumAuth.ForgotPassword"), model));
            }

            // var membershipHelper = new MembershipHelper(UmbracoContext.Current);
            var memberService = Services.MemberService;

            // var member = membershipHelper.GetByEmail(model.EmailAddress);
            var member = memberService.GetByEmail(model.EmailAddress);

            if (member != null)
            {
                // we found a user with that email ....
                DateTime expires = DateTime.Now.AddMinutes(20);
                var      guid    = new Guid("00000000-0000-0000-0000-" + expires.ToString("ddMMyyHHmmss"));
                //00000000-0000-0000-0000-ddMMyyHHmmss
                member.SetValue(ForumAuthConstants.ResetRequestGuidPropery, guid);
                memberService.Save(member);

                // send email....
                ForumEmailHelper helper = new ForumEmailHelper();
                helper.SendResetPassword(Umbraco, member.Email, guid.ToString());

                TempData["ResetSent"] = true;
            }
            else
            {
                ModelState.AddModelError(ForumAuthConstants.ForgotPasswordKey,
                                         Umbraco.GetDictionaryValue("MemberAuth.Reset.NoUser", "No user found"));
                return(PartialView(Umbraco.GetDictionaryValue("ForumAuthConstants.ForgotPasswordView", "Member/ForumAuth.ForgotPassword")));
            }

            return(CurrentUmbracoPage());
        }
        public ActionResult HandleRegister(ForumRegisterViewModel model)
        {
            TempData["RegisterComplete"] = false;

            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            var memberService = Services.MemberService;

            if (EmailAddressExists(model.EmailAddress))
            {
                ModelState.AddModelError(ForumAuthConstants.RegisterKey,
                                         Umbraco.GetDictionaryValue("MemberAuth.Register.ExistingEmail", "Email Address is already in use"));
                return(CurrentUmbracoPage());
            }

            if (!IsValidEmailDomain(model.EmailAddress))
            {
                ModelState.AddModelError(ForumAuthConstants.RegisterKey,
                                         Umbraco.GetDictionaryValue("MemberAuth.Register.InvalidDomain", "You cannot register for this site with that email address"));
                return(CurrentUmbracoPage());
            }

            var memberTypeService = Services.MemberTypeService;
            var membertype        = Services.LocalizationService.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType");
            var memberType        = memberTypeService.Get(membertype.GetDefaultValue());

            try
            {
                var newMember = memberService.CreateMemberWithIdentity(
                    model.EmailAddress, model.EmailAddress, model.Name, memberType);

                memberService.SavePassword(newMember, model.Password);
                newMember.SetValue(ForumAuthConstants.AccountVerifiedProperty, false);
                memberService.Save(newMember);

                // add new user to any groups ?
                var groupsToAdd = CurrentPage.Value <string>("defaultMembership");

                if (!string.IsNullOrWhiteSpace(groupsToAdd))
                {
                    var _mgs   = Services.MemberGroupService;
                    var groups = groupsToAdd.Split(',');

                    foreach (var group in groups)
                    {
                        var memberGroup = _mgs.GetByName(group);
                        if (memberGroup != null)
                        {
                            Logger.Info <ForumAuthSurfaceController>("Adding user to group {0}", group);
                            memberService.AssignRole(newMember.Id, group);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(ForumAuthConstants.RegisterKey, "Error creating account:" + ex);
                return(CurrentUmbracoPage());
            }

            // now do the verification stuff.
            var member = memberService.GetByEmail(model.EmailAddress);

            if (member != null)
            {
                member.SetValue(ForumAuthConstants.AccountJoinedDateProperty, DateTime.Now.ToString("dd-MMM-yyyy @ HH:mm:ss"));
                memberService.Save(member);

                // send out the email (use the user key as the guid)
                ForumEmailHelper helper = new ForumEmailHelper();
                helper.SendVerifyAccount(Umbraco, model.EmailAddress, member.Key.ToString());
            }

            TempData["RegisterComplete"] = true;
            return(CurrentUmbracoPage());
        }