Skip to content

Commit

Permalink
style: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet-cetinkaya committed Feb 10, 2024
1 parent a26d9d7 commit 9feda61
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ IAuthenticatorService authenticatorService

public async Task Handle(EnableEmailAuthenticatorCommand request, CancellationToken cancellationToken)
{
User<int, int>? user = await _userService.GetAsync(predicate: u => u.Id == request.UserId, cancellationToken: cancellationToken);
User<int, int>? user = await _userService.GetAsync(
predicate: u => u.Id == request.UserId,
cancellationToken: cancellationToken
);
await _authBusinessRules.UserShouldBeExistsWhenSelected(user);
await _authBusinessRules.UserShouldNotBeHaveAuthenticator(user!);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public async Task<EnabledOtpAuthenticatorResponse> Handle(
CancellationToken cancellationToken
)
{
User<int, int>? user = await _userService.GetAsync(predicate: u => u.Id == request.UserId, cancellationToken: cancellationToken);
User<int, int>? user = await _userService.GetAsync(
predicate: u => u.Id == request.UserId,
cancellationToken: cancellationToken
);
await _authBusinessRules.UserShouldBeExistsWhenSelected(user);
await _authBusinessRules.UserShouldNotBeHaveAuthenticator(user!);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public async Task<LoggedResponse> Handle(LoginCommand request, CancellationToken

AccessToken createdAccessToken = await _authService.CreateAccessToken(user);

Core.Security.Entities.RefreshToken<int, int> createdRefreshToken = await _authService.CreateRefreshToken(user, request.IpAddress);
Core.Security.Entities.RefreshToken<int, int> createdRefreshToken = await _authService.CreateRefreshToken(
user,
request.IpAddress
);
Core.Security.Entities.RefreshToken<int, int> addedRefreshToken = await _authService.AddRefreshToken(createdRefreshToken);
await _authService.DeleteOldRefreshTokens(user.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ await _authService.RevokeDescendantRefreshTokens(
);
await _authBusinessRules.RefreshTokenShouldBeActive(refreshToken);

User<int, int>? user = await _userService.GetAsync(predicate: u => u.Id == refreshToken.UserId, cancellationToken: cancellationToken);
User<int, int>? user = await _userService.GetAsync(
predicate: u => u.Id == refreshToken.UserId,
cancellationToken: cancellationToken
);
await _authBusinessRules.UserShouldBeExistsWhenSelected(user);

Core.Security.Entities.RefreshToken<int, int> newRefreshToken = await _authService.RotateRefreshToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public async Task<RegisteredResponse> Handle(RegisterCommand request, Cancellati

AccessToken createdAccessToken = await _authService.CreateAccessToken(createdUser);

Core.Security.Entities.RefreshToken<int, int> createdRefreshToken = await _authService.CreateRefreshToken(createdUser, request.IpAddress);
Core.Security.Entities.RefreshToken<int, int> createdRefreshToken = await _authService.CreateRefreshToken(
createdUser,
request.IpAddress
);
Core.Security.Entities.RefreshToken<int, int> addedRefreshToken = await _authService.AddRefreshToken(createdRefreshToken);

RegisteredResponse registeredResponse = new() { AccessToken = createdAccessToken, RefreshToken = addedRefreshToken };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentValidation;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using FluentValidation;

namespace Application.Features.Auth.Commands.Register;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public async Task Handle(VerifyOtpAuthenticatorCommand request, CancellationToke
);
await _authBusinessRules.OtpAuthenticatorShouldBeExists(otpAuthenticator);

User<int, int>? user = await _userService.GetAsync(predicate: u => u.Id == request.UserId, cancellationToken: cancellationToken);
User<int, int>? user = await _userService.GetAsync(
predicate: u => u.Id == request.UserId,
cancellationToken: cancellationToken
);
await _authBusinessRules.UserShouldBeExistsWhenSelected(user);

otpAuthenticator!.IsVerified = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ await _userOperationClaimBusinessRules.UserShouldNotHasOperationClaimAlreadyWhen
);
UserOperationClaim<int, int> mappedUserOperationClaim = _mapper.Map(request, destination: userOperationClaim!);

UserOperationClaim<int, int> updatedUserOperationClaim = await _userOperationClaimRepository.UpdateAsync(mappedUserOperationClaim);
UserOperationClaim<int, int> updatedUserOperationClaim = await _userOperationClaimRepository.UpdateAsync(
mappedUserOperationClaim
);

UpdatedUserOperationClaimResponse updatedUserOperationClaimDto = _mapper.Map<UpdatedUserOperationClaimResponse>(
updatedUserOperationClaim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MappingProfiles()
CreateMap<UserOperationClaim<int, int>, DeleteUserOperationClaimCommand>().ReverseMap();
CreateMap<UserOperationClaim<int, int>, DeletedUserOperationClaimResponse>().ReverseMap();
CreateMap<UserOperationClaim<int, int>, GetByIdUserOperationClaimResponse>().ReverseMap();
CreateMap<UserOperationClaim<int, int> , GetListUserOperationClaimListItemDto>().ReverseMap();
CreateMap<UserOperationClaim<int, int>, GetListUserOperationClaimListItemDto>().ReverseMap();
CreateMap<IPaginate<UserOperationClaim<int, int>>, GetListResponse<GetListUserOperationClaimListItemDto>>().ReverseMap();
}
}
16 changes: 13 additions & 3 deletions src/starterProject/Application/Services/AuthService/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public async Task<RefreshToken<int, int>> AddRefreshToken(RefreshToken<int, int>

public async Task DeleteOldRefreshTokens(int userId)
{
List<RefreshToken<int, int>> refreshTokens = await _refreshTokenRepository.GetOldRefreshTokensAsync(userId, _tokenOptions.RefreshTokenTTL);
List<RefreshToken<int, int>> refreshTokens = await _refreshTokenRepository.GetOldRefreshTokensAsync(
userId,
_tokenOptions.RefreshTokenTTL
);
await _refreshTokenRepository.DeleteRangeAsync(refreshTokens);
}

Expand All @@ -59,7 +62,12 @@ public async Task DeleteOldRefreshTokens(int userId)
return refreshToken;
}

public async Task RevokeRefreshToken(RefreshToken<int, int> refreshToken, string ipAddress, string? reason = null, string? replacedByToken = null)
public async Task RevokeRefreshToken(
RefreshToken<int, int> refreshToken,
string ipAddress,
string? reason = null,
string? replacedByToken = null
)
{
refreshToken.RevokedDate = DateTime.UtcNow;
refreshToken.RevokedByIp = ipAddress;
Expand All @@ -77,7 +85,9 @@ public async Task<RefreshToken<int, int>> RotateRefreshToken(User<int, int> user

public async Task RevokeDescendantRefreshTokens(RefreshToken<int, int> refreshToken, string ipAddress, string reason)
{
RefreshToken<int, int>? childToken = await _refreshTokenRepository.GetAsync(predicate: r => r.Token == refreshToken.ReplacedByToken);
RefreshToken<int, int>? childToken = await _refreshTokenRepository.GetAsync(predicate: r =>
r.Token == refreshToken.ReplacedByToken
);

if (childToken?.RevokedDate != null && childToken.ExpiresDate <= DateTime.UtcNow)
await RevokeRefreshToken(childToken, ipAddress, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public async Task VerifyAuthenticatorCode(User<int, int> user, string authentica

private async Task SendAuthenticatorCodeWithEmail(User<int, int> user)
{
EmailAuthenticator<int, int>? emailAuthenticator = await _emailAuthenticatorRepository.GetAsync(predicate: e => e.UserId == user.Id);
EmailAuthenticator<int, int>? emailAuthenticator = await _emailAuthenticatorRepository.GetAsync(predicate: e =>
e.UserId == user.Id
);
if (emailAuthenticator is null)
throw new NotFoundException("Email Authenticator not found.");
if (!emailAuthenticator.IsVerified)
Expand All @@ -102,7 +104,9 @@ private async Task SendAuthenticatorCodeWithEmail(User<int, int> user)

private async Task VerifyAuthenticatorCodeWithEmail(User<int, int> user, string authenticatorCode)
{
EmailAuthenticator<int, int>? emailAuthenticator = await _emailAuthenticatorRepository.GetAsync(predicate: e => e.UserId == user.Id);
EmailAuthenticator<int, int>? emailAuthenticator = await _emailAuthenticatorRepository.GetAsync(predicate: e =>
e.UserId == user.Id
);
if (emailAuthenticator is null)
throw new NotFoundException("Email Authenticator not found.");
if (emailAuthenticator.ActivationKey != authenticatorCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Application.Services.AuthenticatorService;

public interface IAuthenticatorService
{
public Task<EmailAuthenticator<int,int>> CreateEmailAuthenticator(User<int, int> user);
public Task<EmailAuthenticator<int, int>> CreateEmailAuthenticator(User<int, int> user);
public Task<OtpAuthenticator<int, int>> CreateOtpAuthenticator(User<int, int> user);
public Task<string> ConvertSecretKeyToString(byte[] secretKey);
public Task SendAuthenticatorCode(User<int, int> user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

namespace Application.Services.Repositories;

public interface IEmailAuthenticatorRepository : IAsyncRepository<EmailAuthenticator<int, int>, int>, IRepository<EmailAuthenticator<int, int>, int> { }
public interface IEmailAuthenticatorRepository
: IAsyncRepository<EmailAuthenticator<int, int>, int>,
IRepository<EmailAuthenticator<int, int>, int> { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

namespace Application.Services.Repositories;

public interface IOtpAuthenticatorRepository : IAsyncRepository<OtpAuthenticator<int, int>, int>, IRepository<OtpAuthenticator<int, int>, int> { }
public interface IOtpAuthenticatorRepository
: IAsyncRepository<OtpAuthenticator<int, int>, int>,
IRepository<OtpAuthenticator<int, int>, int> { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace Application.Services.Repositories;

public interface IUserOperationClaimRepository : IAsyncRepository<UserOperationClaim<int, int>, int>, IRepository<UserOperationClaim<int, int>, int>
public interface IUserOperationClaimRepository
: IAsyncRepository<UserOperationClaim<int, int>, int>,
IRepository<UserOperationClaim<int, int>, int>
{
Task<IList<OperationClaim<int, int>>> GetOperationClaimsByUserIdAsync(int userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ UserOperationClaimBusinessRules userUserOperationClaimBusinessRules

public async Task<UserOperationClaim<int, int>?> GetAsync(
Expression<Func<UserOperationClaim<int, int>, bool>> predicate,
Func<IQueryable<UserOperationClaim<int, int>>, IIncludableQueryable<UserOperationClaim<int, int> , object>>? include = null,
Func<IQueryable<UserOperationClaim<int, int>>, IIncludableQueryable<UserOperationClaim<int, int>, object>>? include = null,
bool withDeleted = false,
bool enableTracking = true,
CancellationToken cancellationToken = default
Expand Down Expand Up @@ -83,14 +83,18 @@ await _userUserOperationClaimBusinessRules.UserShouldNotHasOperationClaimAlready
userUserOperationClaim.OperationClaimId
);

UserOperationClaim<int, int> updatedUserOperationClaim = await _userUserOperationClaimRepository.UpdateAsync(userUserOperationClaim);
UserOperationClaim<int, int> updatedUserOperationClaim = await _userUserOperationClaimRepository.UpdateAsync(
userUserOperationClaim
);

return updatedUserOperationClaim;
}

public async Task<UserOperationClaim<int, int>> DeleteAsync(UserOperationClaim<int, int> userUserOperationClaim, bool permanent = false)
public async Task<UserOperationClaim<int, int>> DeleteAsync(UserOperationClaim<int, int> userUserOperationClaim, bool permanent = false)
{
UserOperationClaim<int, int> deletedUserOperationClaim = await _userUserOperationClaimRepository.DeleteAsync(userUserOperationClaim);
UserOperationClaim<int, int> deletedUserOperationClaim = await _userUserOperationClaimRepository.DeleteAsync(
userUserOperationClaim
);

return deletedUserOperationClaim;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace Persistence.Repositories;

public class EmailAuthenticatorRepository : EfRepositoryBase<EmailAuthenticator<int, int>, int, BaseDbContext>, IEmailAuthenticatorRepository
public class EmailAuthenticatorRepository
: EfRepositoryBase<EmailAuthenticator<int, int>, int, BaseDbContext>,
IEmailAuthenticatorRepository
{
public EmailAuthenticatorRepository(BaseDbContext context)
: base(context) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace Persistence.Repositories;

public class UserOperationClaimRepository : EfRepositoryBase<UserOperationClaim<int, int>, int, BaseDbContext>, IUserOperationClaimRepository
public class UserOperationClaimRepository
: EfRepositoryBase<UserOperationClaim<int, int>, int, BaseDbContext>,
IUserOperationClaimRepository
{
public UserOperationClaimRepository(BaseDbContext context)
: base(context) { }
Expand Down

0 comments on commit 9feda61

Please sign in to comment.