diff --git a/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java b/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java index 85f65ca6ffe2711377078bc290ad35174364023f..7ca84622cbdab798b161cdf8726b879bea775321 100644 --- a/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java +++ b/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java @@ -5,6 +5,7 @@ import com.safetypin.authentication.exception.InvalidCredentialsException; import com.safetypin.authentication.exception.UserAlreadyExistsException; import com.safetypin.authentication.service.AuthenticationService; import com.safetypin.authentication.service.GoogleAuthService; +import com.safetypin.authentication.service.JwtService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -17,11 +18,13 @@ public class AuthenticationController { private final AuthenticationService authenticationService; private final GoogleAuthService googleAuthService; + private final JwtService jwtService; @Autowired - public AuthenticationController(AuthenticationService authenticationService, GoogleAuthService googleAuthService) { + public AuthenticationController(AuthenticationService authenticationService, GoogleAuthService googleAuthService, JwtService jwtService) { this.authenticationService = authenticationService; this.googleAuthService = googleAuthService; + this.jwtService = jwtService; } @@ -38,19 +41,6 @@ public class AuthenticationController { } - // Endpoint for social registration/login - @PostMapping("/register-social") - public ResponseEntity<AuthResponse> registerSocial(@Valid @RequestBody SocialLoginRequest request) { - try { - String jwt = authenticationService.socialLogin(request); - return ResponseEntity.ok().body(new AuthResponse(true, "OK", new Token(jwt))); - } catch (IllegalArgumentException | UserAlreadyExistsException e) { - AuthResponse response = new AuthResponse(false, e.getMessage(), null); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); - } - - } - // OTP verification endpoint @PostMapping("/verify-otp") public ResponseEntity<AuthResponse> verifyOTP(@RequestParam String email, @RequestParam String otp) { @@ -63,8 +53,6 @@ public class AuthenticationController { } - - // Endpoint for email login @PostMapping("/login-email") public ResponseEntity<AuthResponse> loginEmail(@RequestParam String email, @RequestParam String password) { @@ -78,21 +66,8 @@ public class AuthenticationController { } - // Endpoint for social login (DEPRECATED, use regis-social instead) - @PostMapping("/login-social") - public ResponseEntity<AuthResponse> loginSocial(@RequestParam String email) { - try { - String jwt = authenticationService.loginSocial(email); - return ResponseEntity.ok(new AuthResponse(true, "OK", new Token(jwt))); - } catch (InvalidCredentialsException e){ - AuthResponse response = new AuthResponse(false, e.getMessage(), null); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); - } - - } - @PostMapping("/google") - public ResponseEntity<?> authenticateGoogle(@Valid @RequestBody GoogleAuthDTO googleAuthData) { + public ResponseEntity<AuthResponse> authenticateGoogle(@Valid @RequestBody GoogleAuthDTO googleAuthData) { try { String jwt = googleAuthService.authenticate(googleAuthData); return ResponseEntity.ok(new AuthResponse(true, "OK", new Token(jwt))); @@ -100,7 +75,8 @@ public class AuthenticationController { AuthResponse response = new AuthResponse(false, e.getMessage(), null); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Authentication failed: " + e.getMessage()); + AuthResponse response = new AuthResponse(false, e.getMessage(), null); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } @@ -115,7 +91,7 @@ public class AuthenticationController { @PostMapping("/verify-jwt") public ResponseEntity<AuthResponse> verifyJwtToken(@RequestParam String token) { try { - UserResponse userResponse = authenticationService.getUserFromJwtToken(token); + UserResponse userResponse = jwtService.getUserFromJwtToken(token); return ResponseEntity.ok(new AuthResponse(true, "OK", userResponse)); } catch (InvalidCredentialsException e) { AuthResponse response = new AuthResponse(false, e.getMessage(), null); @@ -123,15 +99,6 @@ public class AuthenticationController { } } - - - - // Endpoint simulating a content post that requires a verified account (DEPRECATED, use be-post instead) - @PostMapping("/post") - public String postContent(@RequestParam String email, @RequestParam String content) { - return authenticationService.postContent(email, content); - } - // On successful login, return an empty map as a placeholder for future reports @GetMapping("/dashboard") public String dashboard() {