Example #1
0
        public async Task <DBStatus> RegisterAsync(UserRegistrationDTO userRegistrationDTO)
        {
            string passwordHash = ConverterSuit.ByteArrayToHex(HashSuit.ComputeSha256(Encoding.UTF8.GetBytes(userRegistrationDTO.Password)));
            User   user         = mapper.Map <User>(userRegistrationDTO);

            user.PasswordHash = passwordHash;
            DBStatus status = await authRepository.RegisterAsync(user);

            return(status);
        }
Example #2
0
        public async Task <LoggedInUserDTO> LoginAsync(UserCredentialsDTO credentialsDTO)
        {
            string passwordHash = ConverterSuit.ByteArrayToHex(HashSuit.ComputeSha256(Encoding.UTF8.GetBytes(credentialsDTO.Password)));
            User   user         = await authRepository.LoginAsync(credentialsDTO.UserId, passwordHash);

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

            LoggedInUserDTO loggedInUser = mapper.Map <LoggedInUserDTO>(user);

            loggedInUser.JwtToken = jwtSuit.GetToken(user);
            return(loggedInUser);
        }
        public async Task <IActionResult> GetStory([Required] Guid storyId)
        {
            ResponseStoryDTO story = await storiesService.GetStoryAsync(storyId);

            if (story == null)
            {
                return(NotFound());
            }

            string etag = ConverterSuit.ByteArrayToHex(HashSuit.ComputeMD5(Encoding.UTF8.GetBytes(story.ToString())));
            string ETag = HttpContext.Request.Headers["If-None-Match"];

            if (etag == ETag)
            {
                return(StatusCode(StatusCodes.Status304NotModified));
            }

            HttpContext.Response.Headers.Add("ETag", new[] { etag });
            return(Ok(story));
        }
Example #4
0
 public Task <DBStatus> UpdateUserPasswordAsync(UpdateUserPasswordDTO passwordDTO)
 {
     passwordDTO.NewPassword = ConverterSuit.ByteArrayToHex(HashSuit.ComputeSha256(Encoding.UTF8.GetBytes(passwordDTO.NewPassword)));
     passwordDTO.OldPassword = ConverterSuit.ByteArrayToHex(HashSuit.ComputeSha256(Encoding.UTF8.GetBytes(passwordDTO.OldPassword)));
     return(userRepository.UpdateUserPasswordAsync(passwordDTO));
 }