From 9d493ac966db2e016f73efcdcfb65dfb10bf8114 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 12 Dec 2018 15:12:27 +0300 Subject: UserInfo -> User --- src/main/java/com/juick/model/UserInfo.java | 60 ----------------------------- 1 file changed, 60 deletions(-) delete mode 100644 src/main/java/com/juick/model/UserInfo.java (limited to 'src/main/java/com/juick/model') diff --git a/src/main/java/com/juick/model/UserInfo.java b/src/main/java/com/juick/model/UserInfo.java deleted file mode 100644 index ca5d75e0..00000000 --- a/src/main/java/com/juick/model/UserInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.juick.model; - -/** - * Created by vt on 03/09/16. - */ -public class UserInfo { - private String fullName; - private String country; - private String url; - private String description; - - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} -- cgit v1.2.3 From 020b4bd111d02fd5273291c85024402ae6c46ab6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 9 Jan 2019 20:11:15 +0300 Subject: Facebook API update --- src/main/java/com/juick/model/facebook/User.java | 70 ---------------------- .../java/com/juick/server/api/ApiSocialLogin.java | 19 +++--- .../juick/server/www/controllers/SocialLogin.java | 19 +++--- .../java/com/juick/service/CrosspostService.java | 4 +- .../com/juick/service/CrosspostServiceImpl.java | 12 ++-- 5 files changed, 24 insertions(+), 100 deletions(-) (limited to 'src/main/java/com/juick/model') diff --git a/src/main/java/com/juick/model/facebook/User.java b/src/main/java/com/juick/model/facebook/User.java index 80838de6..a9288fe4 100644 --- a/src/main/java/com/juick/model/facebook/User.java +++ b/src/main/java/com/juick/model/facebook/User.java @@ -27,98 +27,28 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class User { private String id; private String name; - private String link; - private boolean verified; private String firstName; private String lastName; - private String gender; - private String locale; - private String timezone; - private String updatedTime; private String email; public String getId() { return id; } - public void setId(String id) { - this.id = id; - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - - public String getLink() { - return link; - } - - public void setLink(String link) { - this.link = link; - } - - public boolean getVerified() { - return verified; - } - - public void setVerified(boolean verified) { - this.verified = verified; - } - @JsonProperty("first_name") public String getFirstName() { return firstName; } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } @JsonProperty("last_name") public String getLastName() { return lastName; } - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getLocale() { - return locale; - } - - public void setLocale(String locale) { - this.locale = locale; - } - - public String getTimezone() { - return timezone; - } - - public void setTimezone(String timezone) { - this.timezone = timezone; - } - - @JsonProperty("updated_time") - public String getUpdatedTime() { - return updatedTime; - } - - public void setUpdatedTime(String updatedTime) { - this.updatedTime = updatedTime; - } - public String getEmail() { return email; } diff --git a/src/main/java/com/juick/server/api/ApiSocialLogin.java b/src/main/java/com/juick/server/api/ApiSocialLogin.java index 72cda0af..75fd6d11 100644 --- a/src/main/java/com/juick/server/api/ApiSocialLogin.java +++ b/src/main/java/com/juick/server/api/ApiSocialLogin.java @@ -148,7 +148,7 @@ public class ApiSocialLogin { .state(state) .build(FacebookApi.instance()); OAuth2AccessToken token = facebookService.getAccessToken(code); - final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v2.10/me?fields=id,name,link,verified,email"); + final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v3.2/me?fields=id,name,email"); facebookService.signRequest(token, meRequest); String graph = facebookService.execute(meRequest).getBody(); if (StringUtils.isBlank(graph)) { @@ -157,36 +157,33 @@ public class ApiSocialLogin { } User fb = jsonMapper.readValue(graph, User.class); long fbID = NumberUtils.toLong(fb.getId(), 0); - if (fbID == 0 || StringUtils.isBlank(fb.getName()) || StringUtils.isBlank(fb.getLink())) { - logger.error("Missing required fields, id: {}, name: {}, link: {}", fbID, fb.getName(), fb.getLink()); + if (fbID == 0 || StringUtils.isBlank(fb.getName())) { + logger.error("Missing required fields, id: {}, name: {}", fbID, fb.getName()); throw new HttpBadRequestException(); } int uid = crosspostService.getUIDbyFBID(fbID); if (uid > 0) { - if (!crosspostService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName(), fb.getLink())) { + if (!crosspostService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName())) { logger.error("error updating facebook user, id: {}, token: {}", fbID, token.getAccessToken()); throw new HttpBadRequestException(); } UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl); uriComponentsBuilder.queryParam("hash", userService.getHashByUID(uid)); return "redirect:" + uriComponentsBuilder.build().toUriString(); - } else if (fb.getVerified()) { - if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName(), fb.getLink())) { + } else { + if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName())) { if (StringUtils.isNotEmpty(fb.getEmail())) { - logger.info("found {} for facebook user {}", fb.getEmail(), fb.getLink()); + logger.info("found {} for facebook user {}", fb.getEmail()); Integer userId = crosspostService.getUIDbyFBID(fbID); if (!emailService.getEmails(userId, false).contains(fb.getEmail())) { emailService.addEmail(userId, fb.getEmail()); } } - logger.info("email not found for facebook user {}", fb.getLink()); + logger.info("email not found for facebook user {}", fb.getName()); throw new HttpBadRequestException(); } return "redirect:/signup?type=fb&hash=" + state; - } else { - logger.error("Facebook account is not verified, id: {}", fbID); - throw new HttpBadRequestException(); } }/* @GetMapping("/_twitter") diff --git a/src/main/java/com/juick/server/www/controllers/SocialLogin.java b/src/main/java/com/juick/server/www/controllers/SocialLogin.java index bc631a1a..b071b6ca 100644 --- a/src/main/java/com/juick/server/www/controllers/SocialLogin.java +++ b/src/main/java/com/juick/server/www/controllers/SocialLogin.java @@ -142,7 +142,7 @@ public class SocialLogin { .state(state) .build(FacebookApi.instance()); OAuth2AccessToken token = facebookService.getAccessToken(code); - final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v2.10/me?fields=id,name,link,verified,email"); + final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v3.2/me?fields=id,name,link,verified,email"); facebookService.signRequest(token, meRequest); String graph = facebookService.execute(meRequest).getBody(); if (StringUtils.isBlank(graph)) { @@ -151,14 +151,14 @@ public class SocialLogin { } User fb = jsonMapper.readValue(graph, User.class); long fbID = NumberUtils.toLong(fb.getId(), 0); - if (fbID == 0 || StringUtils.isBlank(fb.getName()) || StringUtils.isBlank(fb.getLink())) { - logger.error("Missing required fields, id: {}, name: {}, link: {}", fbID, fb.getName(), fb.getLink()); + if (fbID == 0 || StringUtils.isBlank(fb.getName())) { + logger.error("Missing required fields, id: {}, name: {}", fbID, fb.getName()); throw new HttpBadRequestException(); } int uid = crosspostService.getUIDbyFBID(fbID); if (uid > 0) { - if (!crosspostService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName(), fb.getLink())) { + if (!crosspostService.updateFacebookUser(fbID, token.getAccessToken(), fb.getName())) { logger.error("error updating facebook user, id: {}, token: {}", fbID, token.getAccessToken()); throw new HttpBadRequestException(); } @@ -166,22 +166,19 @@ public class SocialLogin { c.setMaxAge(50 * 24 * 60 * 60); response.addCookie(c); return "redirect:" + redirectUrl; - } else if (fb.getVerified()) { - if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName(), fb.getLink())) { + } else { + if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName())) { if (StringUtils.isNotEmpty(fb.getEmail())) { - logger.info("found {} for facebook user {}", fb.getEmail(), fb.getLink()); + logger.info("found {} for facebook user {}", fb.getEmail()); Integer userId = crosspostService.getUIDbyFBID(fbID); if (!emailService.getEmails(userId, false).contains(fb.getEmail())) { emailService.addEmail(userId, fb.getEmail()); } } - logger.info("email not found for facebook user {}", fb.getLink()); + logger.info("email not found for facebook user {}", fb.getName()); throw new HttpBadRequestException(); } return "redirect:/signup?type=fb&hash=" + state; - } else { - logger.error("Facebook account is not verified, id: {}", fbID); - throw new HttpBadRequestException(); } } @GetMapping("/_twitter") diff --git a/src/main/java/com/juick/service/CrosspostService.java b/src/main/java/com/juick/service/CrosspostService.java index 99911250..28b9e8ab 100644 --- a/src/main/java/com/juick/service/CrosspostService.java +++ b/src/main/java/com/juick/service/CrosspostService.java @@ -60,9 +60,9 @@ public interface CrosspostService { int getUIDbyFBID(long fbID); - boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink); + boolean createFacebookUser(long fbID, String loginhash, String token, String fbName); - boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink); + boolean updateFacebookUser(long fbID, String token, String fbName); int getUIDbyVKID(long vkID); diff --git a/src/main/java/com/juick/service/CrosspostServiceImpl.java b/src/main/java/com/juick/service/CrosspostServiceImpl.java index d190faba..0eeb8c78 100644 --- a/src/main/java/com/juick/service/CrosspostServiceImpl.java +++ b/src/main/java/com/juick/service/CrosspostServiceImpl.java @@ -180,16 +180,16 @@ public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostSe @Transactional @Override - public boolean createFacebookUser(long fbID, String loginhash, String token, String fbName, String fbLink) { - return getJdbcTemplate().update("UPDATE facebook SET fb_id=?, access_token=?, fb_name=?, fb_link=? WHERE loginhash=?", - fbID, token, fbName, fbLink, loginhash) > 0; + public boolean createFacebookUser(long fbID, String loginhash, String token, String fbName) { + return getJdbcTemplate().update("UPDATE facebook SET fb_id=?, access_token=?, fb_name=? WHERE loginhash=?", + fbID, token, fbName, loginhash) > 0; } @Transactional @Override - public boolean updateFacebookUser(long fbID, String token, String fbName, String fbLink) { - return getJdbcTemplate().update("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?", - token, fbName, fbLink, fbID) > 0; + public boolean updateFacebookUser(long fbID, String token, String fbName) { + return getJdbcTemplate().update("UPDATE facebook SET access_token=?,fb_name=? WHERE fb_id=?", + token, fbName, fbID) > 0; } @Transactional(readOnly = true) -- cgit v1.2.3 From 1aea2345966f5026d064a44baaa82bb2d958eb8f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 16 Jan 2019 10:16:24 +0300 Subject: remove unused setters from social bindings --- src/main/java/com/juick/model/twitter/User.java | 4 ---- src/main/java/com/juick/model/vk/Token.java | 14 ++------------ src/main/java/com/juick/model/vk/User.java | 18 ++---------------- src/main/java/com/juick/model/vk/UsersResponse.java | 4 ---- 4 files changed, 4 insertions(+), 36 deletions(-) (limited to 'src/main/java/com/juick/model') diff --git a/src/main/java/com/juick/model/twitter/User.java b/src/main/java/com/juick/model/twitter/User.java index 3c80eff4..22f44cf6 100644 --- a/src/main/java/com/juick/model/twitter/User.java +++ b/src/main/java/com/juick/model/twitter/User.java @@ -31,8 +31,4 @@ public class User { public String getScreenName() { return screenName; } - - public void setScreenName(String screenName) { - this.screenName = screenName; - } } diff --git a/src/main/java/com/juick/model/vk/Token.java b/src/main/java/com/juick/model/vk/Token.java index ed93a3ab..15645f99 100644 --- a/src/main/java/com/juick/model/vk/Token.java +++ b/src/main/java/com/juick/model/vk/Token.java @@ -17,11 +17,13 @@ package com.juick.model.vk; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by vitalyster on 28.11.2016. */ +@JsonIgnoreProperties(ignoreUnknown = true) public class Token { private Long userId; private String accessToken; @@ -32,25 +34,13 @@ public class Token { return userId; } - public void setUserId(Long userId) { - this.userId = userId; - } - @JsonProperty("access_token") public String getAccessToken() { return accessToken; } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - @JsonProperty("expires_in") public String getExpiresIn() { return expiresIn; } - - public void setExpiresIn(String expiresIn) { - this.expiresIn = expiresIn; - } } diff --git a/src/main/java/com/juick/model/vk/User.java b/src/main/java/com/juick/model/vk/User.java index aeb18285..7eb03182 100644 --- a/src/main/java/com/juick/model/vk/User.java +++ b/src/main/java/com/juick/model/vk/User.java @@ -17,11 +17,13 @@ package com.juick.model.vk; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by vitalyster on 28.11.2016. */ +@JsonIgnoreProperties(ignoreUnknown = true) public class User { private String id; private String firstName; @@ -33,33 +35,17 @@ public class User { return firstName; } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - @JsonProperty("last_name") public String getLastName() { return lastName; } - public void setLastName(String lastName) { - this.lastName = lastName; - } - @JsonProperty("screen_name") public String getScreenName() { return screenName; } - public void setScreenName(String screenName) { - this.screenName = screenName; - } - public String getId() { return id; } - - public void setId(String id) { - this.id = id; - } } diff --git a/src/main/java/com/juick/model/vk/UsersResponse.java b/src/main/java/com/juick/model/vk/UsersResponse.java index 67505703..d82b0c4b 100644 --- a/src/main/java/com/juick/model/vk/UsersResponse.java +++ b/src/main/java/com/juick/model/vk/UsersResponse.java @@ -31,8 +31,4 @@ public class UsersResponse { public List getUsers() { return users; } - - public void setUsers(List users) { - this.users = users; - } } -- cgit v1.2.3