Exemplo n.º 1
0
        public IActionResult changeemail(ResetEmailViewModel model)
        {
            ViewData["Page"] = "change-email";
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Home/index.cshtml", model));
            }

            // validate id and key
            if (UserBLL.Validate_User_Key(_context, model.Id, model.Code))
            {
                // update email
                UserBLL.Update_Field_Id(_context, model.Id, "email", model.Email);

                var user = SiteConfig.userManager.FindByIdAsync(model.Id).Result;
                if (user != null)
                {
                    _emailSender.ChangeEmailResetCompletedAsync(_context, user.Email, user.UserName);
                }
            }
            else
            {
                throw new ApplicationException(SiteConfig.generalLocalizer["_email_reset_failed"].Value);
            }

            ViewData["Page"] = "signin";
            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }