Ejemplo n.º 1
0
  public static User getLoggedUser(Class<? extends SunshineUser> c) {
    ParseUser currentUser = ParseUser.getCurrentUser();
    if (currentUser != null) {

      if (user == null) user = new User();

      if (currentUser.get("facebookData") == null) {
        user.setImg(currentUser.getParseFile("img").getUrl());
      } else {

        try {
          JSONObject fb = new JSONObject(currentUser.getString("facebookData"));
          String id = fb.getString("id");
          user.setImg("https://graph.facebook.com/" + id + "/picture?type=large");
        } catch (JSONException e) {
          e.printStackTrace();
        }
      }
      user.setEmail(currentUser.getEmail());
      user.setName(currentUser.getString("name"));
      user.setUserName(currentUser.getUsername());
      user.setObjectId(currentUser.getObjectId());
      user.setCreatedAt(currentUser.getCreatedAt());
      user.setUpdateAt(currentUser.getUpdatedAt());
      return user;
    } else {
      return null;
    }
  }
Ejemplo n.º 2
0
  public void siginUpFB(User user, String data, SunshineFacebookLoginCallback callback) {

    this.facebookLoginCallback = callback;

    parseUser = new ParseUser();
    parseUser.setEmail(user.getEmail());
    parseUser.setUsername(user.getUserName());
    parseUser.setPassword(user.getPassword());
    // prepareParseUser(parseUser, user);
    parseUser.put("name", user.getName());

    parseUser.put("facebookData", data);

    ParseUser.logInInBackground(
        user.getUserName(),
        user.getPassword(),
        new LogInCallback() {
          @Override
          public void done(ParseUser user, ParseException e) {
            if (user != null) facebookLoginCallback.doneLoginFacebook(true);
            else
              parseUser.signUpInBackground(
                  new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                      if (e == null) facebookLoginCallback.doneLoginFacebook(true);
                      else facebookLoginCallback.doneLoginFacebook(false);
                    }
                  });
          }
        });
  }
Ejemplo n.º 3
0
  public void siginUp(User user, SunshineLoginCallback callback) {

    this.callback = callback;

    parseUser = new ParseUser();
    parseUser.setEmail(user.getEmail());
    parseUser.setUsername(user.getUserName());
    parseUser.setPassword(user.getPassword());
    // prepareParseUser(parseUser, user);
    parseUser.put("name", user.getName());

    if (user.getImgPath() != null) {
      File file = new File(user.getImgPath());
      parseFile = new ParseFile(file);
      parseFile.saveInBackground(
          new SaveCallback() {
            @Override
            public void done(ParseException e) {
              if (e != null) e.printStackTrace();
              parseUser.put("img", parseFile);
              parseUser.signUpInBackground(SunshineLogin.this);
            }
          });
    } else {
      parseUser.signUpInBackground(SunshineLogin.this);
    }
  }