use of org.mamute.auth.SignupInfo in project mamute by caelum.
the class LoginMethodManager method merge.
public boolean merge(MethodType type, SocialAPI socialApi) {
Optional<SignupInfo> optional = socialApi.getSignupInfo();
if (!optional.isPresent())
return false;
SignupInfo signupInfo = optional.get();
User existantGoogleUser = users.findByEmailAndMethod(signupInfo.getEmail(), type);
if (existantGoogleUser != null) {
access.login(existantGoogleUser);
return true;
}
String token = socialApi.getAccessToken().getToken();
User existantUser = users.findByEmail(signupInfo.getEmail());
if (existantUser != null) {
mergeLoginMethod.mergeLoginMethods(token, existantUser, type);
return true;
}
createNewUser(token, signupInfo, type);
return true;
}
use of org.mamute.auth.SignupInfo in project mamute by caelum.
the class SignupInfoTest method should_build_info_from_facebook_json.
@Test
public void should_build_info_from_facebook_json() {
InputStream is = getClass().getResourceAsStream("/facebook-user.json");
String json = new Scanner(is).useDelimiter("$$").next();
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
SignupInfo info = SignupInfo.fromFacebook(jsonObject).get();
assertEquals("chico@brutal.com", info.getEmail());
assertEquals("Francisco Sokol", info.getName());
assertEquals("São Paulo, Brazil", info.getLocation());
assertTrue(info.getPhotoUri().getPath().contains("100001959511194"));
assertEquals(MethodType.FACEBOOK, info.getMethod());
}
Aggregations