Ejemplo n.º 1
0
        public async Task <IActionResult> UpdatePassword(int accountId, [FromBody] AccountChangePwDTO changePwDTO)
        {
            try
            {
                var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                if (userId != accountId)
                {
                    return(Unauthorized());
                }
                var result = await _repo.ChangePassword(accountId, changePwDTO.CurrentPassword, changePwDTO.NewPassword);

                if (result)
                {
                    return(Ok());
                }
                return(BadRequest(new
                {
                    Error = "Mật khẩu cũ không chính xác"
                }));
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordSaveDto resourceSave)
        {
            _auditTrailRepo.User = User;
            var changepassword = await _repo.ChangePassword(_auditTrailRepo.AuthenticatedUserDetails.Id, resourceSave);

            if (changepassword.HasError)
            {
                await _auditTrailRepo.SaveFailedTrail(new AuditTrailFailedSaveDto()
                {
                    Action       = TransactionType.CHANGEPASSWORD,
                    Activity     = $"Change Password User:{_auditTrailRepo.AuthenticatedUserDetails.UserInCharge}",
                    ErrorMessage = changepassword.Message
                });

                return(BadRequest(changepassword.Message));
            }
            return(Ok("Change Password Done!"));
        }