コード例 #1
0
        public async Task <IActionResult> ResetPassword(PasswordResetVeiwModel model)
        {
            //var userName = User.Claims.FirstOrDefault().Value;
            var result = "error";

            if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.OldPassword) && !string.IsNullOrEmpty(model.Password))
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                await _userManager.ChangePasswordAsync(user, model.OldPassword, model.Password);

                result = "success";
            }
            else
            {
                return(Ok(result));
            }

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IActionResult> ForgetPassword(PasswordResetVeiwModel model)
        {
            var result = "error";

            if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.ConfirmPassword))
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                await _userManager.RemovePasswordAsync(user);

                if (user.PasswordHash == null)
                {
                    await _userManager.AddPasswordAsync(user, model.Password);
                }

                result = "success";
            }
            else
            {
                return(Ok(result));
            }

            return(Ok(result));
        }