Skip to content
This repository was archived by the owner on Jul 21, 2024. It is now read-only.
Open
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
21 changes: 21 additions & 0 deletions server/Controllers/ChatHttpController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,25 @@ public async Task<ActionResult> Join([FromBody] ChatJoinRequest chatJoinRequest)

return Ok();
}

[HttpGet]
public async Task<ActionResult> ChatLog(long roomId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보안을 위한 작업이 추가로 필요할 것 같습니다.

만약에 RoomID가 탈취 되었을 경우 해당 채팅 방에서의 모든 채팅 기록을 받아볼 수 있을 가능성이 있어보입니다.

여러 방법이 있겠지만 JWT 인증을 통해 payload의 UserID(고유값)을 취하고 이를 Room 내 속해있는 유저인지 확인하는 작업이 추가되면 이를 개선할 수 있지 않을까 하는 제안을 해봅니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추석때 쉬라매!!!!!!!!!!!!!!!!!

{
var chatLogResponse = await _chatHttpService.ChatLog(roomId);

if (chatLogResponse == null) return NotFound();

JwtSecurityToken jwtToken = HttpContext.GetJwtToken();
long id = long.Parse(jwtToken.GetClaimByType("id"));

foreach (var response in chatLogResponse)
{
if (response.sender == id)
{
return Ok(chatLogResponse);
}
}

return Unauthorized();
}
}
10 changes: 10 additions & 0 deletions server/DTOs/chat/ChatLogResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace server.DTOs;

public class ChatLogResponse
{
public long sender { get; set; }

public string message { get; set; }

public DateTime datetime { get; set; }
}
3 changes: 1 addition & 2 deletions server/Entities/ChatLogsEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ChatLogsEntity : BaseEntity
public long Receiver { get; set; }

[Required]
public string DateTime { get; set; }
public DateTime DateTime { get; set; }

[Required]
public string Message { get; set; }
Expand All @@ -21,7 +21,6 @@ public class ChatLogsEntity : BaseEntity

public ChatLogsEntity()
{
DateTime = "";
Message = "";
}
}
Expand Down
28 changes: 27 additions & 1 deletion server/Services/ChatHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using server.DTOs;
using System.Data.Entity;
using server.DTOs;
using server.Entities;
using server.Interface;

Expand Down Expand Up @@ -33,4 +34,29 @@ public ChatHttpService(ApplicationDbContext context)

return true;
}

public async Task<List<ChatLogResponse>> ChatLog(long roomId)
{
// RoomId가 동일한 채팅 기록들을 모두 받아옴
var chatLogs = this._context.ChatLogsEntities.Where(log => log.RoomId == roomId).ToList();
List<ChatLogResponse> chatLogResponses = new List<ChatLogResponse>();

// RoomId가 동일한 채팅 기록이 없는 경우 null을 반환함.
if (chatLogs == null || !chatLogs.Any()) return null;

foreach (var chatLog in chatLogs)
{
ChatLogResponse response = new ChatLogResponse
{
sender = chatLog.Sender,
message = chatLog.Message,
datetime = chatLog.DateTime
};

chatLogResponses.Add(response);
}

return chatLogResponses;
}

}