Esempio n. 1
0
  @Override
  public void onSuccess(final LoginResult loginResult) {
    Log.d("something", "2");
    loginResult.getRecentlyDeniedPermissions();

    Stormpath.socialLogin(
        SocialProvidersResponse.FACEBOOK,
        loginResult.getAccessToken().getToken(),
        null,
        new StormpathCallback<Void>() {
          @Override
          public void onSuccess(Void aVoid) {
            // we are logged in via fb!
            Toast.makeText(
                    LoginActivity.this,
                    "Success! " + loginResult.getAccessToken().getToken(),
                    Toast.LENGTH_LONG)
                .show();
            onLoginSuccessStormpath();
          }

          @Override
          public void onFailure(StormpathError error) {
            Toast.makeText(LoginActivity.this, error.message(), Toast.LENGTH_LONG).show();
          }
        });
  }
Esempio n. 2
0
  // [START handleSignInResult]
  private void handleSignInResult(GoogleSignInResult result) {
    Log.d("Test ", "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
      // Signed in successfully, show authenticated UI.
      GoogleSignInAccount acct = result.getSignInAccount();
      String authCode = acct.getServerAuthCode();
      Log.d("code", authCode);
      // mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
      // updateUI(true);

      //            Stormpath.socialGoogleCodeAuth(SocialProvidersResponse.GOOGLE, new
      // SocialProviderConfiguration(getString(R.string.goog_app_id),
      // getString(R.string.goog_app_id)), new StormpathCallback<String>() {
      //                @Override
      //                public void onSuccess(String s) {
      //                    Log.d("THis worked", s);
      //                }
      //
      //                @Override
      //                public void onFailure(StormpathError error) {
      //
      //                }
      //            });

      Stormpath.socialLogin(
          SocialProvidersResponse.GOOGLE,
          null,
          authCode,
          new StormpathCallback<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
              onLoginSuccessStormpath();
            }

            @Override
            public void onFailure(StormpathError error) {
              Toast.makeText(getBaseContext(), "Log in failed", Toast.LENGTH_SHORT).show();
            }
          });

    } else {
      // Signed out, show unauthenticated UI.
      // updateUI(false);
    }
  }
Esempio n. 3
0
  public void onLoginSuccessStormpath() {
    _loginButton.setEnabled(true);
    // TODO: save token in shared prefs
    // SharedPreferences sharedPref =
    // getBaseContext().getSharedPreferences("com.pk.tagger.PREFERENCE_FILE_KEY",
    // Context.MODE_PRIVATE);
    // SharedPreferences.Editor editor = sharedPref.edit();
    // editor.putString(getString(R.string.access_token), token);
    // editor.commit();

    Log.d("Success Stormpath", "this worked");

    Stormpath.getUserProfile(
        new StormpathCallback<UserProfile>() {
          @Override
          public void onSuccess(UserProfile userProfile) {
            // user data ready

            Log.d("success", userProfile.getEmail());
            Log.d("success", Stormpath.accessToken());
            session.createLoginSession(userProfile.getEmail(), Stormpath.accessToken());

            Intent intent = new Intent(getBaseContext(), MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            // intent.putExtra("Username", name);
            startActivity(intent);
          }

          @Override
          public void onFailure(StormpathError error) {
            // something went wrong
            Log.d("success", "this didn't work");
          }
        });

    // Toast.makeText(getBaseContext(), "Login successful", Toast.LENGTH_LONG).show();
    // Intent intent = new Intent(getBaseContext(), MainActivity.class);

    // intent.putExtra("Username", name);
    // startActivity(intent);
    // finish();
  }
Esempio n. 4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    session = new SessionManager(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("user_status", "email"));
    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
    LoginManager.getInstance().registerCallback(callbackManager, this);

    if (BuildConfig.DEBUG) {
      // we only want to show the logs in debug builds, for easier debugging
      Stormpath.setLogLevel(StormpathLogger.VERBOSE);
    }

    // initialise login button below
    _loginButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            login();
          }
        });

    // intialise Register link below
    _registerLink.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Start register activity
            Toast.makeText(getApplicationContext(), "Register is selected!", Toast.LENGTH_SHORT)
                .show();
            Intent intent = new Intent(getApplicationContext(), RegisterActivity.class);
            startActivityForResult(intent, REQUEST_REGISTER);
          }
        });

    _skiploginLink.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Start register activity
            Toast.makeText(getApplicationContext(), "Skipping login!", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
          }
        });

    String serverClientId = getString(R.string.goog_app_id);
    GoogleSignInOptions gso =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(Scopes.EMAIL))
            .requestServerAuthCode(serverClientId, false)
            .build();

    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setScopes(gso.getScopeArray());

    signInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Log.d("google click", "test ");
            signIn();
          }
        });
  }