Search in sources :

Example 1 with SignupInfo

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;
}
Also used : User(org.mamute.model.User) SignupInfo(org.mamute.auth.SignupInfo)

Example 2 with SignupInfo

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());
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) SignupInfo(org.mamute.auth.SignupInfo) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Aggregations

SignupInfo (org.mamute.auth.SignupInfo)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 InputStream (java.io.InputStream)1 Scanner (java.util.Scanner)1 Test (org.junit.Test)1 User (org.mamute.model.User)1