com.google.firebase.auth.FirebaseUser Java Examples
The following examples show how to use
com.google.firebase.auth.FirebaseUser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 8 votes |
public void getUserProfile() { // [START get_user_profile] FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { // Name, email address, and profile photo Url String name = user.getDisplayName(); String email = user.getEmail(); Uri photoUrl = user.getPhotoUrl(); // Check if user's email is verified boolean emailVerified = user.isEmailVerified(); // The user's ID, unique to the Firebase project. Do NOT use this value to // authenticate with your backend server, if you have one. Use // FirebaseUser.getIdToken() instead. String uid = user.getUid(); } // [END get_user_profile] }
Example #2
Source File: MainActivity.java From custom-auth-samples with Apache License 2.0 | 7 votes |
/** * Update UI based on Firebase's current user. Show Login Button if not logged in. */ private void updateUI() { FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser(); if (currentUser != null) { binding.setCurrentUser(currentUser); if (currentUser.getPhotoUrl() != null) { Glide.with(this) .load(currentUser.getPhotoUrl()) .into(imageView); } loginButton.setVisibility(View.INVISIBLE); loggedInView.setVisibility(View.VISIBLE); logoutButton.setVisibility(View.VISIBLE); } else { loginButton.setVisibility(View.VISIBLE); loggedInView.setVisibility(View.INVISIBLE); logoutButton.setVisibility(View.INVISIBLE); } }
Example #3
Source File: LoginActivity.java From Password-Storage with MIT License | 7 votes |
private void checkIfEmailVerified(){ FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser(); if (user.isEmailVerified()){ Toast.makeText(getApplicationContext(), R.string.login_successful_login, Toast.LENGTH_SHORT).show(); Intent sendToLogout = new Intent(getApplicationContext(), MainActivity.class); sendToLogout.putExtra("email", str_Email); startActivity(sendToLogout); } else { Toast.makeText(getApplicationContext(), R.string.login_email_notverified,Toast.LENGTH_SHORT).show(); } }
Example #4
Source File: MainActivity.java From protrip with MIT License | 7 votes |
private void onSignedInInitialize(FirebaseUser firebaseUser) { //Firebase Auth User user = new User(firebaseUser.getDisplayName(), firebaseUser.getPhotoUrl(), firebaseUser.getEmail(), firebaseUser.getUid()); mUsername = user.getUsername(); mUserAvatarUrl = user.getAvatarUrl(); mUserEmail = user.getEmailId(); mUid = user.getUid(); tvUserName.setText(mUsername); tvUserEmail.setVisibility(View.VISIBLE); tvUserEmail.setText(mUserEmail); logoutItem.setVisible(true); favoritesItem.setVisible(true); if (mUserAvatarUrl != null) { Picasso.with(this).load(mUserAvatarUrl). placeholder(R.drawable.ic_account_circle_white_24dp). transform(new CircleTransform()). fit(). into(ivAvatar); } }
Example #5
Source File: ChatSignUpActivity.java From chat21-android-sdk with GNU Affero General Public License v3.0 | 6 votes |
private void createUserOnFirebaseAuthentication(final String email, final String password, final OnUserCreatedOnFirebaseCallback onUserCreatedOnFirebaseCallback) { mAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(ChatSignUpActivity.this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { // Toast.makeText(ChatSignUpActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show(); progressBar.setVisibility(View.GONE); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { onUserCreatedOnFirebaseCallback.onUserCreatedError(task.getException()); } else { // user created with success FirebaseUser firebaseUser = mAuth.getCurrentUser(); // retrieve the created user onUserCreatedOnFirebaseCallback.onUserCreatedSuccess(firebaseUser.getUid()); } } }); }
Example #6
Source File: firebaseutils.java From LuxVilla with Apache License 2.0 | 6 votes |
public static void setbio(final TextView bio){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user=auth.getCurrentUser(); FirebaseDatabase database = FirebaseDatabase.getInstance(); if (user !=null){ DatabaseReference myRef = database.getReference("users").child(user.getUid()).child("user_bio"); myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()){ bio.setText(dataSnapshot.getValue(String.class)); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } }
Example #7
Source File: AddUserInteractor.java From firebase-chat with MIT License | 6 votes |
@Override public void addUserToDatabase(final Context context, FirebaseUser firebaseUser) { DatabaseReference database = FirebaseDatabase.getInstance().getReference(); User user = new User(firebaseUser.getUid(), firebaseUser.getEmail(), new SharedPrefUtil(context).getString(Constants.ARG_FIREBASE_TOKEN)); database.child(Constants.ARG_USERS) .child(firebaseUser.getUid()) .setValue(user) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { mOnUserDatabaseListener.onSuccess(context.getString(R.string.user_successfully_added)); } else { mOnUserDatabaseListener.onFailure(context.getString(R.string.user_unable_to_add)); } } }); }
Example #8
Source File: RxFirebaseAuthTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testSignInWithCustomToken_NotSuccessful() { mockNotSuccessfulResult(new IllegalStateException()); when(mockFirebaseAuth.signInWithCustomToken("custom_token")) .thenReturn(mockAuthResultTask); TestObserver<FirebaseUser> obs = TestObserver.create(); RxFirebaseAuth .signInWithCustomToken(mockFirebaseAuth, "custom_token") .subscribe(obs); callOnComplete(mockAuthResultTask); obs.dispose(); // Ensure no more values are emitted after unsubscribe callOnComplete(mockAuthResultTask); obs.assertError(IllegalStateException.class); obs.assertNoValues(); }
Example #9
Source File: AuthPromiseConsumerTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Override public void setup() throws Exception { super.setup(); PowerMockito.mockStatic(FirebaseAuth.class); FirebaseAuth firebaseAuth = PowerMockito.mock(FirebaseAuth.class); Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(Mockito.mock(FirebaseUser.class)); Mockito.when(FirebaseAuth.getInstance()).thenReturn(firebaseAuth); task = Mockito.mock(Task.class); Mockito.when(task.addOnCompleteListener(Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { ((OnCompleteListener) invocation.getArgument(0)).onComplete(task); return null; } }); }
Example #10
Source File: SplashActivity.java From kute with Apache License 2.0 | 6 votes |
private void initFirebase(){ mAuth = FirebaseAuth.getInstance(); 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"); } // ... } }; }
Example #11
Source File: RxFirebaseAuthTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testSignInWithCredential_NotSuccessful() { mockNotSuccessfulResult(new IllegalStateException()); when(mockFirebaseAuth.signInWithCredential(mockAuthCredential)) .thenReturn(mockAuthResultTask); TestObserver<FirebaseUser> obs = TestObserver.create(); RxFirebaseAuth .signInWithCredential(mockFirebaseAuth, mockAuthCredential) .subscribe(obs); callOnComplete(mockAuthResultTask); obs.dispose(); // Ensure no more values are emitted after unsubscribe callOnComplete(mockAuthResultTask); obs.assertError(IllegalStateException.class); obs.assertNoValues(); }
Example #12
Source File: LoginActivity.java From social-app-android with Apache License 2.0 | 6 votes |
private void initFirebaseAuth() { mAuth = FirebaseAuth.getInstance(); if (mAuth.getCurrentUser() != null) { LogoutHelper.signOut(mGoogleApiClient, this); } mAuthListener = firebaseAuth -> { final FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { // Profile is signed in LogUtil.logDebug(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); presenter.checkIsProfileExist(user.getUid()); setResult(RESULT_OK); } else { // Profile is signed out LogUtil.logDebug(TAG, "onAuthStateChanged:signed_out"); } }; }
Example #13
Source File: RxFirebaseUserTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testUnlink() { mockSuccessfulAuthResult(); when(mockFirebaseUser.unlink("provider")) .thenReturn(mockAuthTaskResult); TestObserver<FirebaseUser> obs = TestObserver.create(); RxFirebaseUser.unlink(mockFirebaseUser, "provider") .subscribe(obs); callOnComplete(mockAuthTaskResult); obs.dispose(); // Ensure no more values are emitted after unsubscribe callOnComplete(mockAuthTaskResult); obs.assertComplete(); obs.assertValueCount(1); }
Example #14
Source File: MainActivity.java From custom-auth-samples with Apache License 2.0 | 6 votes |
private void updateUI() { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { mLineLoginButton.setVisibility(View.VISIBLE); mLoggedInView.setVisibility(View.INVISIBLE); } else { Log.d(TAG, "UID = " + user.getUid()); Log.d(TAG, "Provider ID = " + user.getProviderId()); mLineLoginButton.setVisibility(View.INVISIBLE); mLoggedInView.setVisibility(View.VISIBLE); mDisplayNameText.setText(user.getDisplayName()); if (user.getPhotoUrl() != null) { mProfileImageView.setImageUrl(user.getPhotoUrl().toString(), mImageLoader); } } }
Example #15
Source File: AnonymousAuthActivity.java From quickstart-android with Apache License 2.0 | 6 votes |
private void updateUI(FirebaseUser user) { hideProgressBar(); TextView idView = findViewById(R.id.anonymousStatusId); TextView emailView = findViewById(R.id.anonymousStatusEmail); boolean isSignedIn = (user != null); // Status text if (isSignedIn) { idView.setText(getString(R.string.id_fmt, user.getUid())); emailView.setText(getString(R.string.email_fmt, user.getEmail())); } else { idView.setText(R.string.signed_out); emailView.setText(null); } // Button visibility findViewById(R.id.buttonAnonymousSignIn).setEnabled(!isSignedIn); findViewById(R.id.buttonAnonymousSignOut).setEnabled(isSignedIn); findViewById(R.id.buttonLinkAccount).setEnabled(isSignedIn); }
Example #16
Source File: LoginActivity.java From Stayfit with Apache License 2.0 | 6 votes |
private void initializeUserInfo() { FirebaseUser user = mAuth.getCurrentUser(); String userId = user.getUid(); DatabaseReference usersRef = mDatabase.child("Users"); DatabaseReference stepsRef = mDatabase.child("Steps"); DatabaseReference caloriesRef = mDatabase.child("Calories"); User newUser = new User("", "", "", 0, "", 0, 0, 0); usersRef.child(userId).setValue(newUser); Steps steps = new Steps(0); stepsRef.child(userId).setValue(steps); Calories calories = new Calories(0, 0, 0, 0); caloriesRef.child(userId).setValue(calories); }
Example #17
Source File: ChatChannel.java From Shipr-Community-Android with GNU General Public License v3.0 | 6 votes |
private void initVariable() { @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); sdf.setTimeZone(TimeZone.getTimeZone("IST")); mTime = sdf.format(new Date()); // Getting the date final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); mDate = day + "-" + month + "-" + year; mMessage = mEmojiconEditText.getText().toString(); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); uid = Objects.requireNonNull(user).getUid(); if (Objects.requireNonNull(user).getPhotoUrl() != null) { mProfilePic = Objects.requireNonNull(user.getPhotoUrl()).toString(); } }
Example #18
Source File: FirebaseOpsHelper.java From CourierApplication with Mozilla Public License 2.0 | 6 votes |
private void getUserRole(FirebaseUser user) { final DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference(); dbRef.child("users").child(user.getUid()).addListenerForSingleValueEvent( new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot.exists()) { String role = String.valueOf(dataSnapshot.child("role").getValue()); if(role.equals("courier")) { mCurrentOrderInteractor.onUserRoleReceived(true); } else { mCurrentOrderInteractor.onUserRoleReceived(false); } } } @Override public void onCancelled(DatabaseError databaseError) { } } ); }
Example #19
Source File: UserTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Test public void sendEmailVerification_fail() { // Given User user = new User(); FirebaseUser firebaseUser = Mockito.mock(FirebaseUser.class); BiConsumer consumer = Mockito.mock(BiConsumer.class); Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(firebaseUser); Mockito.when(task.isSuccessful()).thenReturn(false); Mockito.when(firebaseUser.sendEmailVerification()).thenReturn(task); // When user.sendEmailVerification().fail(consumer); // Then Mockito.verify(firebaseUser, VerificationModeFactory.times(1)).sendEmailVerification(); Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.nullable(Exception.class)); }
Example #20
Source File: profile.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); btnFBLogout = findViewById(R.id.btnlogout); tvid = findViewById(R.id.tvId); mAuth = FirebaseAuth.getInstance(); FirebaseUser user = mAuth.getCurrentUser(); //String id = user. // tvid.setText(id); btnFBLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mAuth.signOut();//firebase LoginManager.getInstance().logOut();//facebook updateUI(); } }); }
Example #21
Source File: RxFirebaseUserTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testLinkWithCredential_notSuccessful() { mockNotSuccessfulAuthResult(new IllegalStateException()); when(mockFirebaseUser.linkWithCredential(mockAuthCredential)) .thenReturn(mockAuthTaskResult); TestObserver<FirebaseUser> obs = TestObserver.create(); RxFirebaseUser.linkWithCredential(mockFirebaseUser, mockAuthCredential) .subscribe(obs); callOnComplete(mockAuthTaskResult); obs.dispose(); obs.assertError(IllegalStateException.class); }
Example #22
Source File: LogoutHelper.java From social-app-android with Apache License 2.0 | 6 votes |
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { ProfileInteractor.getInstance(fragmentActivity.getApplicationContext()) .removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid()); for (UserInfo profile : user.getProviderData()) { String providerId = profile.getProviderId(); logoutByProvider(providerId, mGoogleApiClient, fragmentActivity); } logoutFirebase(fragmentActivity.getApplicationContext()); } if (clearImageCacheAsyncTask == null) { clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext()); clearImageCacheAsyncTask.execute(); } }
Example #23
Source File: MainActivity.java From quickstart-android with Apache License 2.0 | 6 votes |
private void updateUI(FirebaseUser user) { // Signed in or Signed out if (user != null) { binding.layoutSignin.setVisibility(View.GONE); binding.layoutStorage.setVisibility(View.VISIBLE); } else { binding.layoutSignin.setVisibility(View.VISIBLE); binding.layoutStorage.setVisibility(View.GONE); } // Download URL and Download button if (mDownloadUrl != null) { binding.pictureDownloadUri.setText(mDownloadUrl.toString()); binding.layoutDownload.setVisibility(View.VISIBLE); } else { binding.pictureDownloadUri.setText(null); binding.layoutDownload.setVisibility(View.GONE); } }
Example #24
Source File: TwitterLoginActivity.java From endpoints-samples with Apache License 2.0 | 6 votes |
private void updateUI(FirebaseUser user) { hideProgressDialog(); if (user != null) { mStatusTextView.setText(getString(R.string.twitter_status_fmt, user.getDisplayName())); mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid())); findViewById(R.id.button_twitter_login).setVisibility(View.GONE); findViewById(R.id.button_twitter_signout).setVisibility(View.VISIBLE); } else { mStatusTextView.setText(R.string.signed_out); mDetailTextView.setText(null); findViewById(R.id.button_twitter_login).setVisibility(View.VISIBLE); findViewById(R.id.button_twitter_signout).setVisibility(View.GONE); } }
Example #25
Source File: firebaseutils.java From LuxVilla with Apache License 2.0 | 6 votes |
public static void updateuserbio(String userbio, final LinearLayout linearLayout){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user=auth.getCurrentUser(); FirebaseDatabase database = FirebaseDatabase.getInstance(); if (user !=null) { DatabaseReference myRef = database.getReference("users").child(user.getUid()).child("user_bio"); myRef.setValue(userbio).addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Snackbar.make(linearLayout,"Lamentamos mas ocorreu um erro",Snackbar.LENGTH_LONG).show(); } }); } }
Example #26
Source File: RxFirebaseAuthTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testSignInWithCredential() { mockSuccessfulAuthResult(); when(mockFirebaseAuth.signInWithCredential(mockAuthCredential)) .thenReturn(mockAuthResultTask); TestObserver<FirebaseUser> obs = TestObserver.create(); RxFirebaseAuth .signInWithCredential(mockFirebaseAuth, mockAuthCredential) .subscribe(obs); callOnComplete(mockAuthResultTask); obs.dispose(); // Ensure no more values are emitted after unsubscribe callOnComplete(mockAuthResultTask); obs.assertComplete(); obs.assertValueCount(1); }
Example #27
Source File: MainActivity.java From ChatApp with Apache License 2.0 | 5 votes |
@Override protected void onPause() { super.onPause(); FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser(); if(currentUser != null) { FirebaseDatabase.getInstance().getReference().child("Users").child(currentUser.getUid()).child("online").setValue(ServerValue.TIMESTAMP); } }
Example #28
Source File: AnonymousUpgradeActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private String getUserIdentifier(FirebaseUser user) { if (user.isAnonymous()) { return user.getUid(); } else if (!TextUtils.isEmpty(user.getEmail())) { return user.getEmail(); } else if (!TextUtils.isEmpty(user.getPhoneNumber())) { return user.getPhoneNumber(); } else { return "unknown"; } }
Example #29
Source File: ReferralActivity.java From snippets-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... FirebaseDynamicLinks.getInstance() .getDynamicLink(getIntent()) .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() { @Override public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) { // Get deep link from result (may be null if no link is found) Uri deepLink = null; if (pendingDynamicLinkData != null) { deepLink = pendingDynamicLinkData.getLink(); } // // If the user isn't signed in and the pending Dynamic Link is // an invitation, sign in the user anonymously, and record the // referrer's UID. // FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null && deepLink != null && deepLink.getBooleanQueryParameter("invitedby", false)) { String referrerUid = deepLink.getQueryParameter("invitedby"); createAnonymousAccountWithReferrerInfo(referrerUid); } } }); }
Example #30
Source File: EmailPasswordActivity.java From quickstart-android with Apache License 2.0 | 5 votes |
private void createAccount(String email, String password) { Log.d(TAG, "createAccount:" + email); if (!validateForm()) { return; } showProgressBar(); // [START create_user_with_email] mAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "createUserWithEmail:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "createUserWithEmail:failure", task.getException()); Toast.makeText(EmailPasswordActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } // [START_EXCLUDE] hideProgressBar(); // [END_EXCLUDE] } }); // [END create_user_with_email] }