예제 #1
0
        public async Task <IActionResult> ChangeMyPassword()
        {
            var entity = await _userManager.GetUserAsync(HttpContext.User);

            if (entity == null)
            {
                this.ModelState.AddModelError("", "Sorry, we cannot find the user.");
                return(View(new ApplicationUser()));
            }
            var model = new ChangeMyPassowrdModel();

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> ChangeMyPassword(string id, ChangeMyPassowrdModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            var entity = await _userManager.GetUserAsync(HttpContext.User);

            var results = await _userManager.ChangePasswordAsync(entity, model.CurrentPassword, model.NewPassword);

            results.Errors.ToList().ForEach(x => ModelState.AddModelError(string.Empty, x.Description));
            model.Succeeded = results.Succeeded;
            return(View(model));
        }