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);
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class AuthUI method getDeleteTask.
private Task<Void> getDeleteTask(CredentialTaskApi credentialHelper) {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser == null) {
// If the current user is null, return a failed task immediately
return Tasks.forException(new Exception("No currently signed in user."));
}
// Delete the Firebase user
Task<Void> deleteUserTask = firebaseUser.delete();
// Get all SmartLock credentials associated with the user
List<Credential> credentials = SmartLockBase.credentialsFromFirebaseUser(firebaseUser);
// For each Credential in the list, create a task to delete it.
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(credentialHelper.delete(credential));
}
// Create a combined task that will succeed when all credential delete operations
// have completed (even if they fail).
final Task<Void> combinedCredentialTask = Tasks.whenAll(credentialTasks);
// and return.
return deleteUserTask.continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) throws Exception {
// Call getResult() to propagate failure by throwing an exception
// if there was one.
task.getResult(Exception.class);
// Return the combined credential task
return combinedCredentialTask;
}
});
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class SignedInActivity method populateProfile.
@MainThread
private void populateProfile() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user.getPhotoUrl() != null) {
Glide.with(this).load(user.getPhotoUrl()).fitCenter().into(mUserProfilePicture);
}
mUserEmail.setText(TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail());
mUserDisplayName.setText(TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName());
StringBuilder providerList = new StringBuilder(100);
providerList.append("Providers used: ");
if (user.getProviders() == null || user.getProviders().isEmpty()) {
providerList.append("none");
} else {
Iterator<String> providerIter = user.getProviders().iterator();
while (providerIter.hasNext()) {
String provider = providerIter.next();
if (GoogleAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Google");
} else if (FacebookAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Facebook");
} else if (EmailAuthProvider.PROVIDER_ID.equals(provider)) {
providerList.append("Password");
} else {
providerList.append(provider);
}
if (providerIter.hasNext()) {
providerList.append(", ");
}
}
}
mEnabledProviders.setText(providerList);
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class ChatActivity method attachRecyclerViewAdapter.
private void attachRecyclerViewAdapter() {
Query lastFifty = mChatRef.limitToLast(50);
mAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(Chat.class, R.layout.message, ChatHolder.class, lastFifty) {
@Override
public void populateViewHolder(ChatHolder holder, Chat chat, int position) {
holder.setName(chat.getName());
holder.setText(chat.getMessage());
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null && chat.getUid().equals(currentUser.getUid())) {
holder.setIsSender(true);
} else {
holder.setIsSender(false);
}
}
@Override
protected void onDataChanged() {
// If there are no chat messages, show a view that invites the user to add a message.
mEmptyListMessage.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
};
// Scroll to bottom on new messages
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
mManager.smoothScrollToPosition(mMessages, null, mAdapter.getItemCount());
}
});
mMessages.setAdapter(mAdapter);
}
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]
}
Aggregations