Esempio n. 1
0
        public async Task <ActionResult> ChangeUserPassword(string id, AdminUserChangePasswordViewModel model)
        {
            User user = this.users.GetUser(id).FirstOrDefault();

            IdentityResult result = await userManager.RemovePasswordAsync(user);

            if (result.Succeeded)
            {
                result = await userManager.AddPasswordAsync(user, model.NewPassword);
            }

            TempData.AddSuccessMessage($"Password for {user.UserName} changed successfuly.");

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <ActionResult> ChangeUserPassword([FromRoute(Name = "id")] string id, [FromBody] AdminUserChangePasswordModel model)
        {
            User user = this.users.GetUser(id).FirstOrDefault();

            if (user == null)
            {
                return(NotFound("No such user exists."));
            }

            IdentityResult result = await userManager.RemovePasswordAsync(user);

            if (result.Succeeded)
            {
                result = await userManager.AddPasswordAsync(user, model.NewPassword);
            }

            return(Ok());
        }