Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (token) : invalidation #124

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<IActionResult> GetCategories(int pageNumber = 0, int pageSize
public async Task<IActionResult> GetAllCategoriesWithOutPagination()
{
var categories = await _categoryService.GetAllCategoriesWithoutPaginationAsync();
return Ok(categories);
return Ok(categories.Categories);
}

[Authorize(Policy = "silver")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ namespace AnalysisData.Dtos.GraphDto.CategoryDto;
public class GetAllCategoryDto
{
public IEnumerable<Category> Categories;

public GetAllCategoryDto(IEnumerable<Category> categories)
{
Categories = categories;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AnalysisData.Repositories.PasswordResetTokensRepository.Abstraction;
public interface IPasswordResetTokensRepository
{
Task AddToken(PasswordResetToken token);
Task<PasswordResetToken> GetToken(Guid guid);
Task<PasswordResetToken> GetToken(Guid guid, string token);
Task SaveChange();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public async Task AddToken(PasswordResetToken token)
await _context.SaveChangesAsync();
}

public async Task<PasswordResetToken> GetToken(Guid userId)
public async Task<PasswordResetToken> GetToken(Guid userId, string token)
{
return await _context.Tokens.Include(x => x.User).OrderByDescending(x => x.Id)
.FirstOrDefaultAsync(x => x.UserId == userId);
return await _context.Tokens
.Include(x => x.User)
.FirstOrDefaultAsync(x => x.UserId == userId && x.Token == token);
}

public async Task SaveChange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<PaginationCategoryDto> GetAllCategoriesAsync(int pageNumber, i
public async Task<GetAllCategoryDto> GetAllCategoriesWithoutPaginationAsync()
{
var allCategoryDto = await _categoryRepository.GetAllAsync();
return new GetAllCategoryDto() { Categories = allCategoryDto};
return new GetAllCategoryDto(allCategoryDto);
}

public async Task AddAsync(NewCategoryDto categoryDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ public ValidateTokenService(IPasswordResetTokensRepository resetTokensRepository

public async Task ValidateResetToken(Guid userId, string resetPasswordToken)
{
var resetToken = await _resetTokensRepository.GetToken(userId);
var resetToken = await _resetTokensRepository.GetToken(userId,resetPasswordToken);
if (resetToken == null || resetToken.IsUsed)
throw new TokenIsInvalidException();
if (resetPasswordToken != resetToken.Token)
throw new TokenIsInvalidException();
if (resetToken.Expiration < DateTime.UtcNow)
throw new TokenExpiredException();

Expand Down
Loading