Esempio n. 1
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordBM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (model.NewPassword.CompareTo(model.ConfirmNewPassword) != 0)
            {
                return(BadRequest()); // NewPassword and ConfirmPassword are valid but do not match
            }
            MyUser user = _context.Users.Cast <MyUser>().Single(x => x.UserName == HttpContext.User.Identity.Name);

            if (user == null)
            {
                return(BadRequest());
            }

            var result = await _userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest()); //current password is incorrect
            }
            return(Ok());
        }
        public async Task <IHttpActionResult> ChangePassword(ChangePasswordBM m)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var res = await UserManager.ChangePasswordAsync(UserId,
                                                            m.OldPassword, m.NewPassword);

            if (!res.Succeeded)
            {
                return(GetErrorResult(res));
            }

            return(Ok());
        }