示例#1
0
        public ActionResult ChangeEmail(ChangeEmailModel model)
        {
            if (!User.Identity.IsAuthenticated)
                return Redirect("/");

            var profile = db.UserProfiles.First(p => p.UserName == User.Identity.Name);
            model.Email = profile.Email;

            return View(model);
        }
示例#2
0
        public ActionResult ChangeEmail_Post(ChangeEmailModel model)
        {
            if (!User.Identity.IsAuthenticated)
                return Redirect("/");

            if (String.IsNullOrEmpty(model.Password))
            {
                return RedirectToAction("ChangeEmail",
                    new { userMessage = "Please enter your password to make this change." });
            }

            if (String.IsNullOrEmpty(model.Email))
            {
                return RedirectToAction("ChangeEmail",
                    new { userMessage = "Please enter the e-mail you wish to use." });
            }

            //check password.
            MembershipUser u = Membership.GetUser(User.Identity.Name);

            if (!Membership.ValidateUser(User.Identity.Name, model.Password))
            {
                return RedirectToAction("ChangeEmail",
                    new { userMessage = "Please enter your password to make this change." });
            }

            var profile = db.UserProfiles.First(p => p.UserName == User.Identity.Name);
            profile.Email = model.Email;
            db.SaveChanges();

            return RedirectToAction("ChangeEmail");
        }