示例#1
0
        public async Task <ServiceResponse <string> > ChangePassword(UserChangeDto userChangeDto)
        {
            ServiceResponse <string> response = new ServiceResponse <string>();
            User user = await _context.Users.FirstOrDefaultAsync(x => x.Email.ToLower().Equals(userChangeDto.Email.ToLower()));

            if (user == null)
            {
                response.Success = false;
                response.Message = "User not found.";
            }
            else if (!VerifyPasswordHash(userChangeDto.Password, user.PasswordHash, user.PasswordSalt) && !VerifyPasswordHash(userChangeDto.Password, user.SecondPasswordHash, user.PasswordSalt))
            {
                response.Success = false;
                response.Message = "Wrong password";
            }
            else
            {
                Utility.CreatePasswordHash(userChangeDto.NewPassword, out byte[] passwordHash, out byte[] passwordSalt);
                user.PasswordHash       = passwordHash;
                user.SecondPasswordHash = passwordHash;
                user.PasswordSalt       = passwordSalt;
                _context.Users.Update(user);
                await _context.SaveChangesAsync();

                response.Data    = "You password has succesfully been changed, you will be logged out.";
                response.Message = "You password has succesfully been changed, you will be logged out.";
            }
            return(response);
        }
示例#2
0
        public async Task <IActionResult> ChangePassword(UserChangeDto request)
        {
            ServiceResponse <string> response = await _authRepo.ChangePassword(request);

            if (!response.Success)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }
示例#3
0
        public void Execute(UserChangeDto request)
        {
            _validator.ValidateAndThrow(request);
            var user = _context.Users.Find(request.Id);

            if (user == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(WatchShop.Domain.User));
            }
            if (_actor.Id != user.Id)
            {
                throw new UnauthorizedAccessException();
            }
            _mapper.Map(request, user);
            _context.SaveChanges();
        }
 public bool UserChange([FromBody] UserChangeDto userDto)
 {
     try
     {
         using (var context = new ServiceContext())
         {
             var userEntity = context.User.Find(userDto.UserID);
             userEntity.PassWord   = MD5Password.Encryption(userDto.PassWord);
             userEntity.Updatetime = DateTime.Now;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public IActionResult Put(int id, [FromBody] UserChangeDto dto, [FromServices] IUpdateUserCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }