Ejemplo n.º 1
0
 private void openSession(
     String applicationId,
     List<String> permissions,
     SessionLoginBehavior behavior,
     int activityCode,
     SessionAuthorizationType authType) {
   if (sessionTracker != null) {
     Session currentSession = sessionTracker.getSession();
     if (currentSession == null || currentSession.getState().isClosed()) {
       Session session =
           new Session.Builder(getActivity()).setApplicationId(applicationId).build();
       Session.setActiveSession(session);
       currentSession = session;
     }
     if (!currentSession.isOpened()) {
       Session.OpenRequest openRequest =
           new Session.OpenRequest(this)
               .setPermissions(permissions)
               .setLoginBehavior(behavior)
               .setRequestCode(activityCode);
       if (SessionAuthorizationType.PUBLISH.equals(authType)) {
         currentSession.openForPublish(openRequest);
       } else {
         currentSession.openForRead(openRequest);
       }
     }
   }
 }
Ejemplo n.º 2
0
 private void onClickLogin() {
   Session session = Session.getActiveSession();
   if (!session.isOpened() && !session.isClosed()) {
     session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
   } else {
     Session.openActiveSession(this, true, statusCallback);
   }
 }
  private void login(JSONArray args, CallbackContext callbackContext) throws JSONException {
    Session session = Session.getActiveSession();

    if (session == null || session.isClosed()) {
      Log.d(TAG, "Building new session");
      session = new Session.Builder(cordova.getActivity()).setApplicationId(this.appId).build();
      Session.setActiveSession(session);
    } else {
      Log.d(TAG, "Existing session " + session.getState());
    }

    if (session.isOpened()) {
      Log.d(TAG, "Session already open");
      callbackContext.success(buildAuthorizationResponse(session));
      return;
    }

    final CallbackContext callback = callbackContext;

    List<String> permissions = new ArrayList<String>();

    permissions.add("basic_info");
    JSONArray argumentPermissions = args.getJSONArray(0);

    for (int i = 0; i < argumentPermissions.length(); i++) {
      permissions.add(argumentPermissions.getString(i));
    }

    OpenRequest openRequest =
        new OpenRequest(cordova.getActivity())
            .setPermissions(permissions)
            .setCallback(
                new StatusCallback() {
                  @Override
                  public void call(Session session, SessionState state, Exception exception) {
                    Log.d(TAG, "In status callback open for read " + state);

                    if (state == SessionState.OPENING) {
                      return;
                    }

                    session.removeCallback(this);

                    try {
                      JSONObject response = buildAuthorizationResponse(session);

                      callback.success(response);
                    } catch (JSONException e) {
                      Log.e(TAG, "JSONException", e);
                      callback.error(e.toString());
                    }
                  }
                });

    cordova.setActivityResultCallback(this);

    session.openForRead(openRequest);
  }
Ejemplo n.º 4
0
 public void loginWithFacebook() {
   //  TipsManager.setIsJustLogined(true);
   Session session = Session.getActiveSession();
   if (!session.isOpened() && !session.isClosed()) {
     session.openForRead(new Session.OpenRequest(activity).setCallback(facebookStatusCallback));
   } else {
     Session.openActiveSession(activity, true, facebookStatusCallback);
   }
 }
Ejemplo n.º 5
0
 public void onClickLogin() {
   Session session = Session.getActiveSession();
   if (!session.isOpened() && !session.isClosed()) {
     session.openForRead(
         new Session.OpenRequest(mContext).setPermissions(this.mPermissions).setCallback(this));
   } else {
     Session.openActiveSession(mContext, true, this);
   }
 }
  private Session getSession() {
    Session session = Session.getActiveSession();

    if (session == null || session.getState().isClosed()) {
      Log.d(TAG, "building session");
      session = new Session.Builder(cordova.getActivity()).setApplicationId(this.appId).build();

      if (session.getState() == SessionState.CREATED_TOKEN_LOADED) {
        Log.d(TAG, "opening session");
        session.openForRead(null);
      }

      Session.setActiveSession(session);
    }

    return session;
  }
Ejemplo n.º 7
0
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   mHelper.onResume();
   if (!hasTryLogin) {
     if (FacebookUtil.isFacebookVlidate(this)) mAction = PendingAction.NONE;
     else mAction = PendingAction.GET_INFO;
     Session session = Session.getActiveSession();
     if (session != null && (!session.isOpened() && !session.isClosed())) {
       session.openForRead(
           new Session.OpenRequest(this).setPermissions(null).setCallback(mCallback));
     } else {
       Session.openActiveSession(this, true, mCallback);
     }
   }
 }
Ejemplo n.º 8
0
  private void initFacebook(Bundle savedInstanceState) {
    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session != null) {
      return;
    }
    if (savedInstanceState != null) {
      session = Session.restoreSession(activity, null, facebookStatusCallback, savedInstanceState);
    }
    if (session == null) {
      session = new Session(activity);
    }
    Session.setActiveSession(session);
    if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
      session.openForRead(new Session.OpenRequest(activity).setCallback(facebookStatusCallback));
    }
  }
Ejemplo n.º 9
0
 private void loadAccessToken() {
   String access_token = prefs.getString(ACCESS_TOKEN, null);
   long expires = 0;
   if (prefs != null) {
     expires = prefs.getLong(ACCESS_EXPIRES, 0);
     if (access_token != null) {
       facebook.setAccessToken(access_token);
       Session session = new Session(getApplicationContext());
       Session.setActiveSession(session);
       FacebookSessionStatusCallback statusCallback = new FacebookSessionStatusCallback();
       session.openForRead(new Session.OpenRequest(TelaFacebook.this).setCallback(statusCallback));
       pegarUsuario();
     }
     if (expires != 0) {
       facebook.setAccessExpires(expires);
     }
   } else {
     System.out.println("Sem internet");
   }
 }
Ejemplo n.º 10
0
  public void doLogin() {
    // mDialog.show();
    Session session = new Session(mContext.getApplicationContext());
    Session.setActiveSession(session);

    session.openForRead(
        new Session.OpenRequest(mFragment)
            .setPermissions(Arrays.asList("email"))
            .setCallback(
                new Session.StatusCallback() {

                  @Override
                  public void call(final Session session, SessionState sessionState, Exception e) {
                    if (session.isOpened()) {

                      // make request to the /me API
                      Request.newMeRequest(
                              session,
                              new Request.GraphUserCallback() {

                                // callback after Graph API response with user object
                                @Override
                                public void onCompleted(final GraphUser user, Response response) {
                                  if (user != null) {

                                    final String email = user.getProperty("email").toString();

                                    Log.w(TAG, "email is " + email);
                                  }
                                }
                              })
                          .executeAsync();
                    } else if (session.isClosed()) {
                      Log.w(TAG, "Facebook is a different user");
                    }
                  }
                }));
  }
  public static void ui(String params, int cbIndex) {
    Session session = Session.getActiveSession();
    if (session == null) {
      session = new Session(mContext);
      Session.setActiveSession(session);
    }

    if (session.isOpened()) {
      Message message = myHandler.obtainMessage(MyHandler.EXECUTE_WEBDIALOG, params);
      message.arg1 = cbIndex;
      message.sendToTarget();
    } else {
      mStatusCallback.mCallByMode = SessionStatusCallback.CallByFBUI;
      mStatusCallback.mCallbackIndex = cbIndex;
      mStatusCallback.params = params;

      if (!session.isClosed()) {
        session.openForRead(new Session.OpenRequest(mActivity).setCallback(mStatusCallback));
      } else {
        Session.openActiveSession(mActivity, true, mStatusCallback);
      }
    }
  }
Ejemplo n.º 12
0
 static void sessionOpenRequest(
     Session session,
     Session.StatusCallback callback,
     Activity activity,
     List<String> permissions,
     boolean publish) {
   if (session.isOpened()) {
     Session.NewPermissionsRequest req =
         getNewPermissionsRequest(session, callback, permissions, activity);
     if (publish) {
       session.requestNewPublishPermissions(req);
     } else {
       session.requestNewReadPermissions(req);
     }
   } else {
     OpenRequest req = getOpenRequest(callback, permissions, activity);
     if (publish) {
       session.openForPublish(req);
     } else {
       session.openForRead(req);
     }
   }
 }
    @Override
    public void onClick(View v) {
      Context context = getContext();
      final Session openSession = sessionTracker.getOpenSession();
      if (openSession != null) {
        // If the Session is currently open, it must mean we need to log out
        if (confirmLogout) {
          // Create a confirmation dialog
          String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
          String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
          String message;
          if (user != null && user.getName() != null) {
            message =
                String.format(
                    getResources().getString(R.string.com_facebook_loginview_logged_in_as),
                    user.getName());
          } else {
            message =
                getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
          }
          AlertDialog.Builder builder = new AlertDialog.Builder(context);
          builder
              .setMessage(message)
              .setCancelable(true)
              .setPositiveButton(
                  logout,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      openSession.closeAndClearTokenInformation();
                    }
                  })
              .setNegativeButton(cancel, null);
          builder.create().show();
        } else {
          openSession.closeAndClearTokenInformation();
        }
      } else {
        Session currentSession = sessionTracker.getSession();
        if (currentSession == null || currentSession.getState().isClosed()) {
          sessionTracker.setSession(null);
          Session session = new Session.Builder(context).setApplicationId(applicationId).build();
          Session.setActiveSession(session);
          currentSession = session;
        }
        if (!currentSession.isOpened()) {
          Session.OpenRequest openRequest = null;
          if (parentFragment != null) {
            openRequest = new Session.OpenRequest(parentFragment);
          } else if (context instanceof Activity) {
            openRequest = new Session.OpenRequest((Activity) context);
          }

          if (openRequest != null) {
            openRequest.setDefaultAudience(properties.defaultAudience);
            openRequest.setPermissions(properties.permissions);
            openRequest.setLoginBehavior(properties.loginBehavior);

            if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
              currentSession.openForPublish(openRequest);
            } else {
              currentSession.openForRead(openRequest);
            }
          }
        }
      }
    }
  public static void login(int cbIndex, String scope) {
    Log.i(TAG, "dsafsdfas");
    Session session = Session.getActiveSession();
    if (session == null) {
      session = new Session(mContext);
      Session.setActiveSession(session);
    }

    String[] permissions = null;
    mNeedPublishPermissions = false;
    if (scope != null) {
      permissions = scope.split(",");
      for (int i = 0; i < permissions.length; i++) {
        if (allPublishPermissions.contains(permissions[i])) {
          mNeedPublishPermissions = true;
          break;
        }
      }
    }

    if (session.isOpened()) {
      Log.i(TAG, "openActiveSession2");
      if (scope == null || session.getPermissions().containsAll(Arrays.asList(permissions))) {
        Log.e(TAG, "FB.login() called when user is already connected.");
      } else {
        mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
        mStatusCallback.mCallbackIndex = cbIndex;
        if (mNeedPublishPermissions) {
          session.requestNewPublishPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        } else {
          session.requestNewReadPermissions(
              new Session.NewPermissionsRequest(mActivity, Arrays.asList(permissions)));
        }
      }
    } else {
      mStatusCallback.mCallByMode = SessionStatusCallback.CallByLogin;
      mStatusCallback.mCallbackIndex = cbIndex;
      Log.i(TAG, "openActiveSession1");
      if (!session.isClosed()) {
        mOpenRequest = new Session.OpenRequest(mActivity);
        if (permissions != null) mOpenRequest.setPermissions(Arrays.asList(permissions));
        mOpenRequest.setCallback(mStatusCallback);

        if (mNeedPublishPermissions) {
          Log.i(TAG, "openActiveSession4");
          session.openForPublish(mOpenRequest);
        } else {
          Log.i(TAG, "openActiveSession5");
          session.openForRead(mOpenRequest);
        }

      } else {
        Log.i(TAG, "openActiveSession");
        Session.openActiveSession(mActivity, true, mStatusCallback);
      }
    }

    /*
     * Session session = Session.getActiveSession(); if (!session.isOpened()
     * && !session.isClosed()) { session.openForRead(new
     * Session.OpenRequest(mActivity)
     * .setPermissions(Arrays.asList("basic_info")).setCallback(
     * mStatusCallback)); } else { Session.openActiveSession(mActivity,
     * true, mStatusCallback); }
     */
  }
Ejemplo n.º 15
0
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.schoolname);

    Bundle b = this.getIntent().getExtras();
    schoolid = b.getInt("school_id");
    String schoolname = b.getString("school_name");
    email = b.getString("email");

    tvSchoolName = (TextView) findViewById(R.id.tvSchoolName);
    tvSchoolName.setTypeface(Fonts.getOpenSansBold(SchoolName.this));
    tvSchoolName.setText(schoolname);

    tvOr = (TextView) findViewById(R.id.tvOr);
    tvOr.setTypeface(Fonts.getOpenSansBold(SchoolName.this));

    bLoginFacebook = (Button) findViewById(R.id.bLoginFacebook);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
      if (savedInstanceState != null) {
        session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
      }
      if (session == null) {
        session = new Session(this);
      }
      Session.setActiveSession(session);
      if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
      }
    }

    // bLoginFacebook.setText(R.string.Log_In);
    bLoginFacebook.setOnClickListener(
        new OnClickListener() {
          public void onClick(View view) {
            onClickLogin();
          }
        });

    bRegister = (Button) findViewById(R.id.bRegister);
    bRegister.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Bundle extras = new Bundle();
            extras.putInt("school_id", schoolid);
            extras.putString("email", email);

            Intent i = new Intent(getApplicationContext(), Register.class);
            i.putExtras(extras);
            startActivity(i);
          }
        });

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.gotoohlala.profile.ProfileSettings");
    brLogout =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            Log.d("onReceive", "Logout in progress");
            // At this point you should start the login activity and finish this one
            finish();
          }
        };
    registerReceiver(brLogout, intentFilter);
  }
Ejemplo n.º 16
0
  public void loginWithFacebook() {
    // start Facebook Login
    Session currentSession = Session.getActiveSession();
    if (currentSession == null || currentSession.getState().isClosed()) {
      Session session = new Session.Builder(this).build();
      Session.setActiveSession(session);
      currentSession = session;
    }

    // Ask for username and password
    Session.OpenRequest op = new Session.OpenRequest(this);

    op.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
    op.setCallback(null);

    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    permissions.add("user_status");
    permissions.add("friends_status");
    permissions.add("read_stream");
    op.setPermissions(permissions);

    Session session = new Session.Builder(LoginActivity.this).build();
    Session.setActiveSession(session);
    session.addCallback(
        new Session.StatusCallback() {

          // callback when session changes state
          @Override
          public void call(Session session, SessionState state, Exception exception) {
            final String accessToken = session.getAccessToken();

            if (session.isOpened()) {
              Request.executeMeRequestAsync(
                  session,
                  new Request.GraphUserCallback() {

                    public void onCompleted(GraphUser user, Response response) {
                      if (user == null) {
                        DialogHelper.showRetryDialog(
                            LoginActivity.this,
                            getString(R.string.could_not_connect_fb_account),
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialogInterface, int i) {
                                loginWithFacebook();
                              }
                            },
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialogInterface, int i) {
                                finish();
                              }
                            });

                      } else {
                        final String name = user.getName();
                        final String email = (String) user.getProperty("email");

                        Toast.makeText(LoginActivity.this, name + " " + email, Toast.LENGTH_LONG)
                            .show();
                        UserHelper.setCurrentUser(user, accessToken);

                        Intent i = new Intent(LoginActivity.this, RevibeActivity.class);
                        startActivity(i);
                        finish();
                      }
                    }
                  });
            }
          }
        });

    session.openForRead(op);
  }