Exemplo n.º 1
0
        public async Task <ActionResult <int> > ChangePassword(int id, [FromBody] UserChangePasswordRequest request)
        {
            var user = await _context
                       .Users
                       .AsNoTracking()
                       .FirstOrDefaultAsync(u => u.UserId == id);

            if (user != null)
            {
                var hash = await HashService.HashPassword(request.OldPassword, user.Salt);

                if (hash == user.Password)
                {
                    var salt    = SaltGenerator.MakeSalty();
                    var newHash = await HashService.HashPassword(request.Password, salt);

                    var newUser = user with {
                        Password = newHash, Salt = salt
                    };

                    _context.Users.Update(newUser);
                    await _context.SaveChangesAsync();

                    return(new OkResult());
                }

                return(new ForbidResult());
            }

            return(new BadRequestResult());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ChangePassword([FromBody] UserChangePasswordRequest userChangePassword)
        {
            var userEmail = User.Claims.FirstOrDefault(c => c.Type == "email")?.Value;

            var user = await _userManager.FindByEmailAsync(userEmail);

            if (user == null)
            {
                return(BadRequest("Invalid User"));
            }

            var correctPassword = await _userManager.CheckPasswordAsync(user, userChangePassword.OldPassword);



            var resp = await _userManager.ChangePasswordAsync(user, userChangePassword.OldPassword, userChangePassword.NewPassword);

            if (!resp.Succeeded)
            {
                return(BadRequest(
                           new ActionResponse
                {
                    Errors = resp.Errors.Select(e => e.Description).ToList(),
                    Success = false
                }
                           ));
            }

            return(Ok("Password changed"));
        }
Exemplo n.º 3
0
 public FinanceResponse ChangePassword(UserChangePasswordRequest request)
 {
     service.ChagePassword(request.Id,
                           CryptInfoHelper.MD5Encode(CryptInfoHelper.GetDecrypte(request.OldPwd)),
                           CryptInfoHelper.MD5Encode(CryptInfoHelper.GetDecrypte(request.NewPwd)));
     return(CreateResponse(FinanceResult.SUCCESS));
 }
Exemplo n.º 4
0
        public async Task <IActionResult> PostChangePassword([FromBody] UserChangePasswordRequest request)
        {
            // TODO: 需要实现修改密码
            await _service.GetByIdAsync(request.Id);

            return(Ok());
        }
Exemplo n.º 5
0
        public async Task <bool> ChangePassword(UserChangePasswordRequest request, CancellationToken cancellationToken = default)
        {
            SetHeader();
            using var responseMessage = await HttpClient.PostAsJsonAsync($"{PrepUrl}/changePassword", request, cancellationToken).ConfigureAwait(false);

            responseMessage.EnsureSuccessStatusCode();
            return(await responseMessage.Content.ReadFromJsonAsync <bool>(cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        public async Task <UpdateStatusViewModel> ChangePassword(UserChangePasswordRequest request)
        {
            var sessions = Core.Token;

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions);
            var json        = JsonConvert.SerializeObject(request);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var response    = await _client.PostAsync($"/api/Users/ChangePassword", httpContent);

            var result = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <UpdateStatusViewModel>(result));
            }
            return(null);
        }
Exemplo n.º 7
0
        public async Task <Response <UserResponse> > ChangePassword(UserChangePasswordRequest request)
        {
            if (request.RequestIdentity.UserId == null)
            {
                return(new Response <UserResponse>(ResponseStatus.BadRequest, null, ResponseMessagesConstans.BadRequest));
            }

            var user = await _uow.Users.FindAsync(new Guid(request.RequestIdentity.UserId));

            if (user == null)
            {
                return(new Response <UserResponse>(ResponseStatus.NotFound, null, ResponseMessagesConstans.NotFound));
            }

            user.Password = _cryptographyLibrary.CalculateHash(request.Password);
            await _uow.Users.ReplaceAsync(user.Id, user);

            return(new Response <UserResponse>(ResponseStatus.Ok, _mapService.MapUser(user)));
        }
Exemplo n.º 8
0
        public async Task <ActionResult <bool> > ChangePassword([FromBody] UserChangePasswordRequest request)
        {
            var user = await UserManager.FindByNameAsync(request.LoginRequest.UserName);

            if (user is null)
            {
                return(NotFound());
            }

            var result = await UserManager.ChangePasswordAsync(user, request.LoginRequest.Password, request.NewPassword);

            if (result.Succeeded)
            {
                return(true);
            }
            else
            {
                return(Unauthorized());
            }
        }
        private async void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckData())
                {
                    //lbInfo.Text = "Please check again data!";
                    return;
                }
                UserChangePasswordRequest request = new UserChangePasswordRequest();
                request.Password        = txtPassword.Text.Trim();
                request.ConfirmPassword = txtConfirmPassword.Text.Trim();
                request.Username        = txtUsername.Text.Trim();
                request.PasswordOld     = txtPasswordOld.Text.Trim();
                var data = await _Controller.ChangePassword(request);

                if (data != null)
                {
                    if (data.Status == Utilities.Common.UpdateStatus.Successfull)
                    {
                        lbInfo.Text = data.Message;;
                    }
                    else
                    {
                        lbInfo.Text = data.Message;
                    }
                    return;
                }
                else
                {
                    lbInfo.Text = "No reponse";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.ToString()}");
            }
        }
Exemplo n.º 10
0
        public Task <MutationResult <bool> > ChangePassword(
            RequestContext requestContext,
            [ApiDescription("The user current password")] string oldPassword,
            [ApiDescription("The user new password")] string newPassword)
        {
            var user = requestContext?.Authentication?.User as UserDescription;

            if (user == null)
            {
                return(Task.FromResult <MutationResult <bool> >(null));
            }

            var request = new UserChangePasswordRequest
            {
                NewPassword = newPassword,
                OldPassword = oldPassword,
                Login       = user.Login
            };

            return
                (this.system.ActorSelection(NodeManagerApi.GetManagerActorProxyPath())
                 .Ask <MutationResult <bool> >(request, ConfigurationUtils.GetRestTimeout(this.system)));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 更新指定用户的密码
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task <IResponseEntity> UserChangePasswordAsync(UserChangePasswordRequest req)
        {
            if (req == null || req?.Id == "")
            {
                return(ResponseEntity.Error("更新的实体主键丢失"));
            }

            if (req.Password != req.ConfirmPassword)
            {
                return(ResponseEntity.Error("两次密码不一致,请重新输入"));
            }
            var password = MD5Encrypt.Encrypt32(req.Password);
            var item     = new SysUserEntity()
            {
                Id = req.Id, Revision = req.Revision
            };

            _sysUserRepository.Attach(item);            //此时快照 item
            item.Password = password;
            await _sysUserRepository.UpdateAsync(item); //对比快照时的变化


            return(ResponseEntity.Ok("更新成功"));
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> ChangePassword([FromBody] UserChangePasswordRequest request)
        {
            var response = await _userService.ChangePassword(request);

            return(new CreateResult(response));
        }
Exemplo n.º 13
0
 public Task <bool> ChangePassword(UserChangePasswordRequest request, CancellationToken cancellationToken = default) => throw new System.NotImplementedException();
Exemplo n.º 14
0
        public async Task <UpdateStatusViewModel> ChangePassword(UserChangePasswordRequest request)
        {
            var result = await _apiClient.ChangePassword(request);

            return(result);
        }
        public void ChangePassword(UserChangePasswordRequest userChangePasswordRequest)
        {
            if (string.IsNullOrEmpty(userChangePasswordRequest.UserName))
                throw new ArgumentException("Value cannot be null or empty.", "userChangePasswordRequest.UserName");
            if (string.IsNullOrEmpty(userChangePasswordRequest.NewPassword))
                throw new ArgumentException("Value cannot be null or empty.", "userChangePasswordRequest.NewPassword");


            var membershipUser = GetMember(userChangePasswordRequest.UserName);
            if (membershipUser != null)
            {
                var oldPwd = membershipUser.ResetPassword();
                membershipUser.ChangePassword(oldPwd, userChangePasswordRequest.NewPassword);
            }
        }
Exemplo n.º 16
0
 public async Task <IResponseEntity> UserChangePassword(UserChangePasswordRequest req)
 {
     return(await _sysUserService.UserChangePasswordAsync(req));
 }