-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
543e1fd
commit 2c8c0eb
Showing
10 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace MyRecipes.API.Controllers; | ||
|
||
[ApiController] | ||
public class MyRecipesBaseController : ControllerBase | ||
{ | ||
protected static bool IsNotAuthenticated(AuthenticateResult authenticate) | ||
{ | ||
return !authenticate.Succeeded | ||
|| authenticate.Principal is null | ||
|| !authenticate.Principal.Identities.Any(id => id.IsAuthenticated); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,10 @@ | |
}, | ||
"BlobStorage": { | ||
"Azure": "" | ||
}, | ||
"Google": { | ||
"ClientId": "", | ||
"ClientSecret": "" | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/MyRecipes.Application/UseCases/Login/External/ExternalLoginUseCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using MyRecipes.Domain.Repositories; | ||
using MyRecipes.Domain.Repositories.User; | ||
using MyRecipes.Domain.Security.Tokens; | ||
|
||
namespace MyRecipes.Application.UseCases.Login.External; | ||
|
||
public class ExternalLoginUseCase : IExternalLoginUseCase | ||
{ | ||
private readonly IUserReadOnlyRepository _userReadOnlyRepository; | ||
private readonly IUserWriteOnlyRepository _userWriteOnlyRepository; | ||
private readonly IUnitOfWork _unitOfWork; | ||
private readonly IAccessTokenGenerator _accessTokenGenerator; | ||
|
||
public ExternalLoginUseCase( | ||
IUserReadOnlyRepository userReadOnlyRepository, | ||
IUserWriteOnlyRepository userWriteOnlyRepository, | ||
IUnitOfWork unitOfWork, | ||
IAccessTokenGenerator accessTokenGenerator) | ||
{ | ||
_userReadOnlyRepository = userReadOnlyRepository; | ||
_userWriteOnlyRepository = userWriteOnlyRepository; | ||
_unitOfWork = unitOfWork; | ||
_accessTokenGenerator = accessTokenGenerator; | ||
} | ||
|
||
public async Task<string> Execute(string name, string email) | ||
{ | ||
var user = await _userReadOnlyRepository.GetByEmail(email); | ||
|
||
if (user is null) | ||
{ | ||
user = new Domain.Entities.User | ||
{ | ||
Name = name, | ||
Email = email, | ||
Password = "-" | ||
}; | ||
|
||
await _userWriteOnlyRepository.Add(user); | ||
await _unitOfWork.Commit(); | ||
} | ||
|
||
return _accessTokenGenerator.Generate(user.UserIdentifier); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/MyRecipes.Application/UseCases/Login/External/IExternalLoginUseCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace MyRecipes.Application.UseCases.Login.External; | ||
public interface IExternalLoginUseCase | ||
{ | ||
Task<string> Execute(string name, string email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters