Example #1
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            _logger.Info("Changing Password! Params: " + model.ToJson());

            if (!ModelState.IsValid)
            {
                _logger.Error("Changing Password Form Invalid! Errors: " + ModelState.ToJson());
                return(Json(ModelState.ToDictionary()));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                _logger.Info("Changing Password Successfully!");

                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, false, false);
                }
                return(Json("STATUS_OK"));
            }

            AddErrors(result);
            _logger.Error("Changing Password Failed! Errors: " + ModelState.ToJson());

            return(Json(ModelState.ToDictionary()));
        }