From e9d5addc7a0b65c426803171471ca5a042b73c93 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 6 Mar 2025 17:24:15 -0500 Subject: Migrated auth controller methods to auth service --- .../api/ufundapi/controller/AuthController.java | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java index aa27e3f..b9c8ed3 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java @@ -3,22 +3,25 @@ package com.ufund.api.ufundapi.controller; import com.ufund.api.ufundapi.model.UserAuth; import com.ufund.api.ufundapi.persistence.UserAuthDAO; import com.ufund.api.ufundapi.persistence.UserDAO; +import com.ufund.api.ufundapi.service.AuthService; +import com.ufund.api.ufundapi.service.UserService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import javax.net.ssl.HttpsURLConnection; import java.io.IOException; import java.util.Map; @RestController @RequestMapping("auth") public class AuthController { - private final UserDAO userDAO; - private final UserAuthDAO userAuthDAO; + private final UserService userService; + private final AuthService authService; - public AuthController(UserDAO userDAO, UserAuthDAO userAuthDAO) { - this.userDAO = userDAO; - this.userAuthDAO = userAuthDAO; + public AuthController(UserService userService, AuthService authService) { + this.userService = userService; + this.authService = authService; } /** @@ -31,15 +34,12 @@ public class AuthController { String username = params.get("username"); String password = params.get("password"); try { - var usr = userDAO.getUser(username); - if (usr == null || !usr.verifyPassword(password)) { - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); - } - var userAuth = UserAuth.generate(username); - userAuthDAO.addUserAuth(userAuth); - return new ResponseEntity<>(userAuth.getKey(), HttpStatus.OK); + String key = authService.login(username, password); + return new ResponseEntity<>(key, HttpStatus.OK); } catch (IOException ex) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IllegalAccessException e) { + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } } -- cgit v1.2.3 From 1fe3905e9d4354657d22e9dbc1a244108ab55a83 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 6 Mar 2025 17:27:15 -0500 Subject: Removed unused imports and fixed other warnings --- .../java/com/ufund/api/ufundapi/controller/AuthController.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java index b9c8ed3..1a545f6 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java @@ -1,26 +1,20 @@ package com.ufund.api.ufundapi.controller; -import com.ufund.api.ufundapi.model.UserAuth; -import com.ufund.api.ufundapi.persistence.UserAuthDAO; -import com.ufund.api.ufundapi.persistence.UserDAO; import com.ufund.api.ufundapi.service.AuthService; import com.ufund.api.ufundapi.service.UserService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import javax.net.ssl.HttpsURLConnection; import java.io.IOException; import java.util.Map; @RestController @RequestMapping("auth") public class AuthController { - private final UserService userService; private final AuthService authService; - public AuthController(UserService userService, AuthService authService) { - this.userService = userService; + public AuthController(AuthService authService) { this.authService = authService; } -- cgit v1.2.3