Compare commits

...

2 Commits

Author SHA1 Message Date
siujamo 4e2da0debc feat: add expire time into login response 2026-06-04 14:47:45 +08:00
siujamo 0815d1d618 chore: optimise code style 2026-06-04 14:42:14 +08:00
4 changed files with 13 additions and 7 deletions
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Duration;
import java.time.LocalDateTime;
/**
* REST controller for user authentication endpoints (login, logout).
@@ -43,12 +44,14 @@ public class AuthController {
@PostMapping("/login")
public ResponseEntity<UserResponse> login(@Validated @RequestBody LoginRequest request) {
var user = authService.login(request);
var currentTime = LocalDateTime.now();
var accessToken = tokenClient.generateToken(user);
var accessTokenCookie = cookieService.buildCookie(CookieName.ACCESS_TOKEN, accessToken);
var cookieMaxAge = accessTokenCookie.getMaxAge();
return ResponseEntity.ok()
.header(HttpHeaders.SET_COOKIE, accessTokenCookie.toString())
.body(UserResponse.from(user));
.body(UserResponse.from(user, currentTime.plus(cookieMaxAge)));
}
@RequiresAuth
@@ -2,6 +2,8 @@ package com.onixbyte.deltaforceguide.domain.dto;
import com.onixbyte.deltaforceguide.domain.entity.User;
import java.time.LocalDateTime;
/**
* Response DTO for a user account, including associated credentials.
*
@@ -10,13 +12,15 @@ import com.onixbyte.deltaforceguide.domain.entity.User;
public record UserResponse(
Long id,
String username,
String email
String email,
LocalDateTime expiration
) {
public static UserResponse from(User user) {
public static UserResponse from(User user, LocalDateTime expiration) {
return new UserResponse(
user.getId(),
user.getUsername(),
user.getEmail()
user.getEmail(),
expiration
);
}
}
@@ -64,7 +64,7 @@ public class GitHubWebhookInterceptor implements HandlerInterceptor {
var body = req.getBodyString();
try {
var computed = "sha256=" + CryptoUtil.hmacSha256(secret, body);
var computed = "sha256=" + CryptoUtil.hmacSha256(body, secret);
if (!MessageDigest.isEqual(
computed.getBytes(StandardCharsets.UTF_8),
@@ -73,8 +73,7 @@ public class WebhookService {
return;
}
@SuppressWarnings("unchecked")
var data = (Map<String, Object>) yaml.load(parsedYaml);
var data = yaml.<Map<String, Object>>load(parsedYaml);
if (data == null) {
log.warn("Empty YAML block in issue #{}", issue.number());
return;