コード例 #1
0
        public ActionResult Register(AubRegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            var memberService = ApplicationContext.Services.MemberService;

            if (EmailAddressExists(model.EmailAddress))
            {
                ModelState.AddModelError(Form.AubAuthKey,
                                         Localize("Aub.Auth.Register.ExistingEmail", "Email address already registered"));
                return(CurrentUmbracoPage());
            }

            var memberTypeService = ApplicationContext.Services.MemberTypeService;
            var memberType        = memberTypeService.Get("Member");

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

                memberService.SavePassword(member, model.Password);

                if (member.HasProperty(Properties.Verified))
                {
                    member.SetValue(Properties.Verified, false);
                }

                if (member.HasProperty(Properties.ExpiryDate))
                {
                    member.SetValue(Properties.ExpiryDate, DateTime.Now.AddDays(1));
                }

                member.SetValue("umbracoMemberComments",
                                string.Format("{0} {1}", model.EmailAddress, model.Password));

                member.IsApproved = false;
                memberService.Save(member);

                var emailManager = new AuthenticationEmailManager(this.Request);
                emailManager.SendEmail(member.Email,
                                       Localize("Aub.Auth.Verify.Subject", "Verify your account"),
                                       Localize("Aub.Auth.Verify.Email", "{url}"),
                                       member.Key.ToString(),
                                       AuthUrls.Verify);
            }
            catch (Exception ex)
            {
                Logger.Warn <AuthenticationController>("Error while registering {0}", () => ex.ToString());

                ModelState.AddModelError(Form.AubAuthKey,
                                         Localize("Aub.Auth.Register.Error", "An error occured"));
            }

            return(CurrentUmbracoPage());
        }
コード例 #2
0
        public ActionResult ForgotPassword(AubForgotPasswordModel model)
        {
            TempData["resent"] = false;

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

            var memberService = ApplicationContext.Services.MemberService;

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

            if (member != null)
            {
                DateTime expires = DateTime.Now.AddMinutes(30);
                member.SetValue(Properties.ExpiryDate, expires);

                var resetGuid = Guid.NewGuid().ToString();
                member.SetValue(Properties.ResetGuid, resetGuid);
                memberService.Save(member);

                var emailManager = new AuthenticationEmailManager(this.Request);
                emailManager.SendEmail(member.Email,
                                       Localize("Aub.PasswordReset.Subject", "Reset your password"),
                                       Localize("Aub.PasswordReset.Email", "{url}"),
                                       resetGuid,
                                       AuthUrls.Reset);

                TempData["true"] = false;
            }
            else
            {
                ModelState.AddModelError(Form.AubAuthKey,
                                         Localize("Aub.Auth.Reset.NoUser", "No user found"));
            }

            return(CurrentUmbracoPage());
        }