aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-12-21 02:36:49 +0300
committerGravatar Vitaly Takmazov2022-12-21 02:36:49 +0300
commit1ad1b73a7b85e7e907de1870991a8849487f9543 (patch)
tree4cda16090472d739a79ab57efbc94a6ad4e8ddc9 /src/main/java/com/juick/www/api
parent8a32b359eed27ab1d4e054ffed99b6602fa18acf (diff)
Social logins: adopt records
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r--src/main/java/com/juick/www/api/ApiSocialLogin.java29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/main/java/com/juick/www/api/ApiSocialLogin.java b/src/main/java/com/juick/www/api/ApiSocialLogin.java
index 38884cd6..c1e31b68 100644
--- a/src/main/java/com/juick/www/api/ApiSocialLogin.java
+++ b/src/main/java/com/juick/www/api/ApiSocialLogin.java
@@ -149,23 +149,23 @@ public class ApiSocialLogin {
throw new HttpBadRequestException();
}
User fb = jsonMapper.readValue(graph, User.class);
- long fbID = NumberUtils.toLong(fb.getId(), 0);
- if (fbID == 0 || StringUtils.isBlank(fb.getName())) {
- logger.error("Missing required fields, id: {}, name: {}", fbID, fb.getName());
+ long fbID = NumberUtils.toLong(fb.id(), 0);
+ if (fbID == 0 || StringUtils.isBlank(fb.name())) {
+ logger.error("Missing required fields, id: {}, name: {}", fbID, fb.name());
throw new HttpBadRequestException();
}
Optional<com.juick.model.User> existingFacebookUser = userService.getUserByFacebookId(fbID);
if (existingFacebookUser.isPresent()) {
- if (!userService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName())) {
+ if (!userService.updateFacebookUser(fbID, token.getAccessToken(), fb.name())) {
logger.error("error updating facebook user, id: {}, token: {}", fbID, token.getAccessToken());
throw new HttpBadRequestException();
}
- if (StringUtils.isNotEmpty(fb.getEmail())) {
- logger.info("found {} for facebook user {}", fb.getEmail(), fb.getName());
+ if (StringUtils.isNotEmpty(fb.email())) {
+ logger.info("found {} for facebook user {}", fb.email(), fb.name());
Integer userId = existingFacebookUser.get().getUid();
- if (!emailService.getEmails(userId, false).contains(fb.getEmail())) {
- emailService.addEmail(userId, fb.getEmail());
+ if (!emailService.getEmails(userId, false).contains(fb.email())) {
+ emailService.addEmail(userId, fb.email());
}
}
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl);
@@ -173,7 +173,7 @@ public class ApiSocialLogin {
uriComponentsBuilder.queryParam("retpath", redirectUrl);
return "redirect:" + uriComponentsBuilder.build().toUriString();
} else {
- if (!userService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName())) {
+ if (!userService.createFacebookUser(fbID, state, token.getAccessToken(), fb.name())) {
throw new HttpBadRequestException();
}
return "redirect:/signup?type=fb&hash=" + state;
@@ -199,16 +199,16 @@ public class ApiSocialLogin {
vkAuthService.signRequest(token, meRequest);
String graph = vkAuthService.execute(meRequest).getBody();
- com.juick.model.ext.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).getUsers().get(0);
- String vkName = jsonUser.getFirstName() + " " + jsonUser.getLastName();
- String vkLink = jsonUser.getScreenName();
+ com.juick.model.ext.vk.User jsonUser = jsonMapper.readValue(graph, UsersResponse.class).users().get(0);
+ String vkName = jsonUser.firstName() + " " + jsonUser.lastName();
+ String vkLink = jsonUser.screenName();
if (vkName.length() == 1 || StringUtils.isBlank(vkLink)) {
logger.error("vk user error");
throw new HttpBadRequestException();
}
- long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
+ long vkID = NumberUtils.toLong(jsonUser.id(), 0);
int uid = userService.getUIDbyVKID(vkID);
if (uid > 0) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl);
@@ -226,8 +226,7 @@ public class ApiSocialLogin {
}
@ResponseBody
@PostMapping("/api/_google")
- public AuthResponse googleSignIn(@RequestParam(name = "idToken") String idTokenString)
- throws GeneralSecurityException, IOException {
+ public AuthResponse googleSignIn(@RequestParam(name = "idToken") String idTokenString) {
logger.info("Token: {}", idTokenString);
logger.info("Client: {}", googleClientId);
Optional<String> verifiedEmail = GoogleTokenVerifier.validateToken(googleClientId, idTokenString);