aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java13
-rw-r--r--juick-www/src/main/java/com/juick/www/facebook/User.java5
2 files changed, 16 insertions, 2 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java b/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java
index cb55bf82..95ed9a5b 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/FacebookLogin.java
@@ -25,6 +25,7 @@ import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.OAuth20Service;
import com.juick.server.util.HttpBadRequestException;
import com.juick.service.CrosspostService;
+import com.juick.service.EmailService;
import com.juick.service.UserService;
import com.juick.www.Utils;
import com.juick.www.facebook.User;
@@ -69,6 +70,8 @@ public class FacebookLogin {
private CrosspostService crosspostService;
@Inject
private UserService userService;
+ @Inject
+ private EmailService emailService;
@PostConstruct
public void init() {
@@ -89,7 +92,7 @@ public class FacebookLogin {
OAuth20Service facebookAuthService = serviceBuilder
.apiSecret(FACEBOOK_SECRET)
.callback(FACEBOOK_REDIRECT)
- .scope("publish_actions")
+ .scope("publish_actions,email")
.state(fbstate)
.build(FacebookApi.instance());
return "redirect:" + facebookAuthService.getAuthorizationUrl();
@@ -109,7 +112,7 @@ public class FacebookLogin {
.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");
+ final OAuthRequest meRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v2.10/me?fields=id,name,link,verified,email");
facebookService.signRequest(token, meRequest);
String graph = facebookService.execute(meRequest).getBody();
if (StringUtils.isBlank(graph)) {
@@ -134,6 +137,12 @@ public class FacebookLogin {
} else if (fb.getVerified()) {
String loginhash = UUID.randomUUID().toString();
if (!crosspostService.createFacebookUser(fbID, loginhash, token.getAccessToken(), fb.getName(), fb.getLink())) {
+ if (StringUtils.isNotEmpty(fb.getEmail())) {
+ Integer userId = crosspostService.getUIDbyFBID(fbID);
+ if (!emailService.getEmails(userId, false).contains(fb.getEmail())) {
+ emailService.addEmail(userId, fb.getEmail());
+ }
+ }
throw new HttpBadRequestException();
}
return "redirect:/signup?type=fb&hash=" + loginhash;
diff --git a/juick-www/src/main/java/com/juick/www/facebook/User.java b/juick-www/src/main/java/com/juick/www/facebook/User.java
index 77f23ac9..b56c4ee3 100644
--- a/juick-www/src/main/java/com/juick/www/facebook/User.java
+++ b/juick-www/src/main/java/com/juick/www/facebook/User.java
@@ -35,6 +35,7 @@ public class User {
private String locale;
private String timezone;
private String updatedTime;
+ private String email;
public String getId() {
return id;
@@ -117,4 +118,8 @@ public class User {
public void setUpdatedTime(String updatedTime) {
this.updatedTime = updatedTime;
}
+
+ public String getEmail() {
+ return email;
+ }
}