Skip to content

Commit

Permalink
Merge pull request #7 from KYJKY/master
Browse files Browse the repository at this point in the history
JWT, Refresh Token 추가
  • Loading branch information
KYJKY authored Jan 31, 2024
2 parents 5f281bb + e86b1cb commit 5ee2a8e
Show file tree
Hide file tree
Showing 27 changed files with 1,633 additions and 77 deletions.
3 changes: 3 additions & 0 deletions EveryPinApi.Entites/Models/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class Post
public string? PostContent { get; set; }
[ForeignKey("User")]
public required string UserId { get; set; }
public string? Address { get; set; }
public double? latitude { get; set; }
public double? longitude { get; set; }
public ICollection<PostPhoto> PostPhotos { get; } = new List<PostPhoto>();
public ICollection<Like> Likes { get; } = new List<Like>();
public ICollection<Comment> Comments { get; } = new List<Comment>();
Expand Down
2 changes: 2 additions & 0 deletions EveryPinApi.Entites/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class User : IdentityUser
public ICollection<Like> Like { get; set; } = new List<Like>();
public string? Name { get; set; }
//public string? Email { get; set; }
public string? RefreshToken { get; set; }
public DateTime RefreshTokenExpiryTime { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime LastLoginDate { get; set; }
public bool DeleteCheck { get; set; }
Expand Down
18 changes: 15 additions & 3 deletions EveryPinApi.Presentation/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Service.Contracts;
using Shared.DataTransferObject;
using Shared.DataTransferObject.Auth;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -24,12 +25,11 @@ public AuthenticationController(ILogger<AuthenticationController> logger, IServi
_service = service;
}

[HttpPost]
[HttpPost("regist")]
//[ServiceFilter(typeof(ValidationFilterAttribute))]
public async Task<IActionResult> RegisterUser([FromBody] RegistUserDto registUserDto)
{
var result = await
_service.AuthenticationService.RegisterUser(registUserDto);
var result = await _service.AuthenticationService.RegisterUser(registUserDto);

if (!result.Succeeded)
{
Expand All @@ -42,6 +42,18 @@ public async Task<IActionResult> RegisterUser([FromBody] RegistUserDto registUse

return StatusCode(201);
}

[HttpPost("login")]
public async Task<IActionResult> Authenticate([FromBody] UserAutenticationDto user)
{
if (!await _service.AuthenticationService.ValidateUser(user))
return Unauthorized();

var tokenDto = await _service.AuthenticationService.CreateToken(populateExp: true);

return Ok(tokenDto);

}
}

}
4 changes: 3 additions & 1 deletion EveryPinApi.Presentation/Controllers/CommentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization;

namespace EveryPinApi.Presentation.Controllers
{
Expand All @@ -24,7 +25,8 @@ public CommentController(ILogger<CommentController> logger, IServiceManager serv
_service = service;
}

[HttpGet]
[HttpGet(Name = "GetComment")]
[Authorize(Roles ="NormalUser")]
public IActionResult GetAllComment()
{
var companies = _service.CommentService.GetAllComment(trackChanges: false);
Expand Down
4 changes: 3 additions & 1 deletion EveryPinApi.Presentation/Controllers/LikeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Service.Contracts;
using System;
Expand All @@ -23,6 +24,7 @@ public LikeController(ILogger<LikeController> logger, IServiceManager service)
}

[HttpGet]
[Authorize(Roles = "NormalUser")]
public IActionResult GetAllLike()
{
var likes = _service.LikeService.GetAllLike(trackChanges: false);
Expand Down
4 changes: 3 additions & 1 deletion EveryPinApi.Presentation/Controllers/PostController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Service.Contracts;
using System;
Expand All @@ -23,6 +24,7 @@ public PostController(ILogger<PostController> logger, IServiceManager service)
}

[HttpGet]
[Authorize(Roles = "NormalUser")]
public IActionResult GetAllPost()
{
var posts = _service.PostService.GetAllPost(trackChanges: false);
Expand Down
4 changes: 3 additions & 1 deletion EveryPinApi.Presentation/Controllers/PostPhotoController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Service.Contracts;
using System;
Expand All @@ -23,6 +24,7 @@ public PostPhotoController(ILogger<PostPhotoController> logger, IServiceManager
}

[HttpGet]
[Authorize(Roles = "NormalUser")]
public IActionResult GetAllPostPhoto()
{
var postPhotos = _service.PostPhotoService.GetAllPostPhoto(trackChanges: false);
Expand Down
4 changes: 3 additions & 1 deletion EveryPinApi.Presentation/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Service.Contracts;
using System;
Expand All @@ -23,6 +24,7 @@ public ProfileController(ILogger<ProfileController> logger, IServiceManager serv
}

[HttpGet]
[Authorize(Roles = "NormalUser")]
public IActionResult GetAllProfile()
{
var profiles = _service.ProfileService.GetAllProfile(trackChanges: false);
Expand Down
27 changes: 27 additions & 0 deletions EveryPinApi.Presentation/Controllers/TokenController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Service.Contracts;
using Shared.DataTransferObject.Auth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EveryPinApi.Presentation.Controllers
{
[Route("api/token")]
[ApiController]
public class TokenController : ControllerBase
{
private readonly IServiceManager _service;

public TokenController(IServiceManager service) => _service = service;

[HttpPost("refresh")]
public async Task<IActionResult> Refresh([FromBody] TokenDto tokenDto)
{
var tokenDtoToReturn = await _service.AuthenticationService.RefreshToken(tokenDto);
return Ok(tokenDtoToReturn);
}
}
}
1 change: 1 addition & 0 deletions EveryPinApi/EveryPinApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="7.0.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
Expand Down
Loading

0 comments on commit 5ee2a8e

Please sign in to comment.