diff options
Diffstat (limited to 'src/main/java/com/juick/www/api/ApiSocialLogin.java')
-rw-r--r-- | src/main/java/com/juick/www/api/ApiSocialLogin.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main/java/com/juick/www/api/ApiSocialLogin.java b/src/main/java/com/juick/www/api/ApiSocialLogin.java index e6116173..4b57ce89 100644 --- a/src/main/java/com/juick/www/api/ApiSocialLogin.java +++ b/src/main/java/com/juick/www/api/ApiSocialLogin.java @@ -34,14 +34,14 @@ import com.juick.service.CrosspostService; import com.juick.service.EmailService; import com.juick.service.UserService; import com.juick.util.HttpBadRequestException; +import com.juick.util.HttpForbiddenException; + import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -230,7 +230,7 @@ public class ApiSocialLogin { } @ResponseBody @PostMapping("/api/_google") - public ResponseEntity<AuthResponse> googleSignIn(@RequestParam(name = "idToken") String idTokenString) + public AuthResponse googleSignIn(@RequestParam(name = "idToken") String idTokenString) throws GeneralSecurityException, IOException { logger.info("Token: {}", idTokenString); logger.info("Client: {}", googleClientId); @@ -241,16 +241,16 @@ public class ApiSocialLogin { if (visitor.isAnonymous()) { String verificationCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase(); emailService.addVerificationCode(null, email, verificationCode); - return ResponseEntity.ok(new AuthResponse(null, email, verificationCode)); + return new AuthResponse(null, email, verificationCode); } else { - return ResponseEntity.ok(new AuthResponse(users.getMe(visitor), null, null)); + return new AuthResponse(users.getMe(visitor), null, null); } } - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null); + throw new HttpForbiddenException(); } @ResponseBody @PostMapping("/api/signup") - public ResponseEntity<com.juick.model.User> signupWithEmail(String username, String password, String verificationCode) { + public com.juick.model.User signupWithEmail(String username, String password, String verificationCode) { if (username.length() < 2 || username.length() > 16 || !username.matches("^[a-zA-Z0-9\\-]+$") || password.length() < 6 || password.length() > 32) { throw new HttpBadRequestException(); @@ -261,9 +261,9 @@ public class ApiSocialLogin { com.juick.model.User newUser = userService.createUser(username, password).orElseThrow(HttpBadRequestException::new); emailService.addEmail(newUser.getUid(), verifiedEmail); emailService.deleteAuthCode(verificationCode); - return ResponseEntity.ok(newUser); + return newUser; } else { - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null); + throw new HttpForbiddenException(); } } @GetMapping("/api/_applelogin") |