Search in sources :

Example 11 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project RSAndroidApp by RailwayStations.

the class SignInActivity method handleFirebaseAuthResult.

private void handleFirebaseAuthResult(AuthResult authResult) {
    if (authResult != null) {
        // Welcome the user
        FirebaseUser user = authResult.getUser();
        Toast.makeText(this, "Welcome " + user.getEmail(), Toast.LENGTH_SHORT).show();
        // Go back to the main activity
        startActivity(new Intent(this, AuthActivity.class));
    }
}
Also used : Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 12 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project priend by TakoJ.

the class ProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    firebaseAuth = FirebaseAuth.getInstance();
    FirebaseUser user = firebaseAuth.getCurrentUser();
    mStorageRef = FirebaseStorage.getInstance().getReference();
    SharedPreferences sharedPreferences = getSharedPreferences("email", Context.MODE_PRIVATE);
    //유저 uid받기
    userUid = sharedPreferences.getString("uid", user.getUid());
    //유저 email(아이디)받기
    userEmail = sharedPreferences.getString("email", user.getEmail());
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference();
    if (firebaseAuth.getCurrentUser() == null) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
    }
    // 이 activity가 켜졌을 때 권한설정 물어보기
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
        }
    }
    // butterknife: view binder , list adapter 할때도 간편한 코드 구현가능
    petImage = (ImageView) findViewById(R.id.petImage);
    btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
    textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
    textViewUserEmail.setText(user.getEmail() + "님의 반려동물");
    buttonLogout = (Button) findViewById(R.id.buttonLogout);
    buttonLogout.setOnClickListener(this);
    petImage = (ImageView) findViewById(R.id.petImage);
    btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
    petName = (EditText) findViewById(R.id.petName);
    petAge = (EditText) findViewById(R.id.petAge);
    radiogroup_gender = (RadioGroup) findViewById(R.id.radiogroup_gender);
    radioGender_male = (RadioButton) findViewById(R.id.radioGender_male);
    radioGender_female = (RadioButton) findViewById(R.id.radioGender_female);
    radiogroup_type = (RadioGroup) findViewById(R.id.radiogroup_type);
    radio_dog = (RadioButton) findViewById(R.id.radio_dog);
    radio_cat = (RadioButton) findViewById(R.id.radio_cat);
    radiogroup_size = (RadioGroup) findViewById(R.id.radiogroup_size);
    radioSize_small = (RadioButton) findViewById(R.id.radioSize_small);
    radioSize_middle = (RadioButton) findViewById(R.id.radioSize_middle);
    radioSize_large = (RadioButton) findViewById(R.id.radioSize_large);
    btn_profilefinish = (Button) findViewById(R.id.btn_profilefinish);
    btn_UploadPicture.setOnClickListener(this);
    btn_profilefinish.setOnClickListener(this);
    loadSavedPreferences();
    //원래 사진받아오는 자리
    new DownloadImage().execute();
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) SharedPreferences(android.content.SharedPreferences) DatabaseReference(com.google.firebase.database.DatabaseReference) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 13 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.

the class FacebookLoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_facebook);
    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    findViewById(R.id.button_facebook_signout).setOnClickListener(this);
    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]
    // [START auth_state_listener]
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // [START_EXCLUDE]
            updateUI(user);
        // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]
    // [START initialize_fblogin]
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            // [START_EXCLUDE]
            updateUI(null);
        // [END_EXCLUDE]
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            // [START_EXCLUDE]
            updateUI(null);
        // [END_EXCLUDE]
        }
    });
// [END initialize_fblogin]
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) LoginButton(com.facebook.login.widget.LoginButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 14 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.

the class RegisterEmailFragment method registerUser.

private void registerUser(final String email, final String name, final String password) {
    mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            // Set display name
            UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
            final FirebaseUser user = authResult.getUser();
            user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {

                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    // This executes even if the name change fails, since
                    // the account creation succeeded and we want to save
                    // the credential to SmartLock (if enabled).
                    mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
                }
            });
        }
    }).addOnFailureListener(getActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mHelper.dismissDialog();
            if (e instanceof FirebaseAuthWeakPasswordException) {
                // Password too weak
                mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
            } else if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Email address is malformed
                mEmailInput.setError(getString(R.string.invalid_email_address));
            } else if (e instanceof FirebaseAuthUserCollisionException) {
                // Collision with existing user email, it should be very hard for
                // the user to even get to this error due to CheckEmailFragment.
                mEmailInput.setError(getString(R.string.error_user_collision));
            } else {
                // General error message, this branch should not be invoked but
                // covers future API changes
                mEmailInput.setError(getString(R.string.email_account_creation_error));
            }
        }
    });
}
Also used : TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) UserProfileChangeRequest(com.google.firebase.auth.UserProfileChangeRequest) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 15 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordPromptTest method testSignInButton_signsInAndSavesCredentials.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignInButton_signsInAndSavesCredentials() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    WelcomeBackPasswordPrompt welcomeBackActivity = createActivity();
    EditText passwordField = (EditText) welcomeBackActivity.findViewById(R.id.password);
    passwordField.setText(TestConstants.PASSWORD);
    FirebaseUser mockFirebaseUser = mock(FirebaseUser.class);
    when(ActivityHelperShadow.sFirebaseAuth.signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    Button signIn = (Button) welcomeBackActivity.findViewById(R.id.button_done);
    signIn.performClick();
    verify(ActivityHelperShadow.sFirebaseAuth).signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD);
    verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) EditText(android.widget.EditText) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) WelcomeBackPasswordPrompt(com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)26 AuthResult (com.google.firebase.auth.AuthResult)7 Button (android.widget.Button)6 FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)6 BuildConfig (com.firebase.ui.auth.BuildConfig)5 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)5 Test (org.junit.Test)5 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)4 Config (org.robolectric.annotation.Config)4 NonNull (android.support.annotation.NonNull)3 EditText (android.widget.EditText)3 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 Task (com.google.android.gms.tasks.Task)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FirebaseAuthWeakPasswordException (com.google.firebase.auth.FirebaseAuthWeakPasswordException)2