private void createUserProfile(String name, String uid, String email) { FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference(); User user = new User(uid, name, email); myRef.child("users").child(uid).setValue(user); FirebaseUser currentUser = mAuth.getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(name).build(); currentUser.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()) { Log.d(TAG, "User display_name added"); } } } ); }
public void AddUserInfoRequest(String name, String url, final AccountDetailsInteractor.OnAccountDetailsListener listener){ Uri picUri = Uri.parse(url); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(name) .setPhotoUri(picUri) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { listener.onUserInfoUpdateSuccess(); } } }); }
public void AddUserInfoRequest(String name, String url, final OnSettingsFinishedListener listener){ Uri picUri = Uri.parse(url); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(name) .setPhotoUri(picUri) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { listener.onUserInfoUpdateSuccess(); } } }); }
@OnClick(R.id.editProfileButton) public void editProfileClick() { String name = nameEditText.getText().toString(); if(!name.isEmpty()) { UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(name) .build(); CheckLoginActivity.user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Toast.makeText(getBaseContext(), R.string.edit_profile_changed, Toast.LENGTH_SHORT).show(); finish(); } } }); } else { nameEditText.setError(getString(R.string.profile_name_edit_error)); } }
private void updateProfile() { // [START update_profile] FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName("Jane Q. User") .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg")) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User profile updated."); } } }); // [END update_profile] }
private void signUp() { if (hasAccepted) { showingSignUp = false; firebaseAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { if (task.getException() != null) Toast.makeText(LoginActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show(); } else { UserProfileChangeRequest profileChangeRequest = new UserProfileChangeRequest.Builder() .setDisplayName(name) .build(); user = firebaseAuth.getCurrentUser(); UserInformation userInformation = new UserInformation(name, name.toLowerCase()); if (user != null) { user.updateProfile(profileChangeRequest); String userId = user.getUid(); ref.child("users").child(userId).setValue(userInformation); } setLoginView(); } } }); } else { ((CheckBox) findViewById(R.id.agree_check)).setError(getString(R.string.error_field_required)); } }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { if (s.equals("mobile_network")) { boolean mobileNetwork = sharedPreferences.getBoolean("mobile_network", true); Intent trackingService = new Intent(this, TrackingService.class); if (mobileNetwork) { startService(trackingService); } else if (Connectivity.isConnectedMobile(this)){ stopService(trackingService); } } else if (s.equals("display_name")) { String name = sharedPreferences.getString(s, "DEFAULT"); databaseReference.child("users").child(userId).child("name").setValue(name); databaseReference.child("users").child(userId).child("caseFoldedName").setValue(name.toLowerCase()); UserProfileChangeRequest profileChangeRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).build(); firebaseUser.updateProfile(profileChangeRequest).addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { setDisplayName(); } }); } }
private void updateProfile(@Nullable String nickname, @Nullable Uri uri) { UserProfileChangeRequest profileUpdates = null; if (nickname != null) { profileUpdates = new UserProfileChangeRequest.Builder().setDisplayName(nickname).build(); } if (uri != null) { profileUpdates = new UserProfileChangeRequest.Builder().setPhotoUri(uri).build(); if (BuildConfig.DEBUG) { Log.d(TAG, "updateProfile Photo uri: " + profileUpdates.getPhotoUri().toString()); } } if (profileUpdates != null) { user.updateProfile(profileUpdates).addOnCompleteListener(task -> { if (task.isSuccessful()) { if (BuildConfig.DEBUG) { Log.d(TAG, "updateProfile: User profile updated."); } if (mUser != null) { BusEventUtils.post(Constants.BUS_FLAG_UPDATE_USER, null); UserUtils.updateUser(user.getUid(), mUser); } } }); } }
public static void setuserfirstdata(final Context context, String username){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user = auth.getCurrentUser(); UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder(); builder.setDisplayName(username); if (user !=null){ user.updateProfile(builder.build()).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (!task.isSuccessful()){ Toast.makeText(context,"Ocorreu um erro",Toast.LENGTH_LONG).show(); } } }); } }
public static void updateusername(String username, final LinearLayout linearLayout){ FirebaseAuth auth=FirebaseAuth.getInstance(); FirebaseUser user=auth.getCurrentUser(); UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder(); builder.setDisplayName(username); if (user !=null){ user.updateProfile(builder.build()).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(); } }); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){ showProgressDialog(); Uri uri = data.getData(); StorageReference filePath = mStorage.child("user-photos").child(user.getUid()).child(uri.getLastPathSegment()); filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { hideProgressDialog(); Uri downloadUri = taskSnapshot.getDownloadUrl(); imageUrl = downloadUri; UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setPhotoUri(downloadUri) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Toast.makeText(UserActivity.this, R.string.upload__success, Toast.LENGTH_SHORT).show(); } } }); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { hideProgressDialog(); Toast.makeText(UserActivity.this, R.string.upload_failure, Toast.LENGTH_SHORT).show(); } }); } }
/** * Updates the user profile information. * * @param firebaseUser current firebaseUser instance. * @param request {@link UserProfileChangeRequest} request for this user. * @return a {@link Completable} if the task is complete successfully. */ @NonNull public static Completable updateProfile(@NonNull final FirebaseUser firebaseUser, @NonNull final UserProfileChangeRequest request) { return Completable.create(new CompletableOnSubscribe() { @Override public void subscribe(CompletableEmitter emitter) throws Exception { RxCompletableHandler.assignOnTask(emitter, firebaseUser.updateProfile(request)); } }); }
@NonNull public static Observable<Void> updateProfile(@NonNull final FirebaseUser firebaseUser, @NonNull final UserProfileChangeRequest request) { return Observable.create(new Observable.OnSubscribe<Void>() { @Override public void call(final Subscriber<? super Void> subscriber) { RxHandler.assignOnTask(subscriber, firebaseUser.updateProfile(request)); } }); }
public String signIn(final String deviceLocalUserId) { String email = idCompatibleString(deviceLocalUserId) + "@" + idCompatibleString(FirebaseInstanceId.getInstance().getId()) + ".example.com"; FirebaseAuth.getInstance().signInWithEmailAndPassword(email, email) .addOnFailureListener(error -> FirebaseAuth.getInstance() // If we can't sign in, try creating account. .createUserWithEmailAndPassword(email, email) .addOnSuccessListener(authResult -> authResult.getUser().updateProfile( new UserProfileChangeRequest.Builder() .setDisplayName(deviceLocalUserId) .build()))); return email; }
private void onAuthSuccess(FirebaseUser user) { UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(String.valueOf(name.getText())) .build(); user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d("TAG", "User profile updated!"); } } }); sendVerificationEmail(getString(R.string.verificationEmail)); }
/** * Register User with Firebase and rename Display nome to chosen name */ // TODO: 16/12/16 Need to send email confirmation if registering with email void register(Context context, String email, String password, String riderName) { checkViewAttached(); getMvpView().showProgress(); auth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener((Activity) context, task -> { if (!task.isSuccessful()) { //registration Failed getMvpView().hideProgress(); BusProvider.getBusProviderInstance().post(new RegisterEvent(false, task.getException().getMessage(), null)); Timber.e("Unsuccessfully Registered : " + task.getException().getMessage()); } else { //registration Successful, change display name FirebaseUser user = task.getResult().getUser(); UserProfileChangeRequest changeRequest = new UserProfileChangeRequest.Builder() .setDisplayName(riderName) .build(); auth.getCurrentUser().updateProfile(changeRequest).addOnCompleteListener(task1 -> { if (task1.isSuccessful()) { //this is needed for display name to show up in auth listener user.reload(); auth.signOut(); auth.signInWithEmailAndPassword(email, password); getMvpView().hideProgress(); } else { Timber.d("Error Changing Display Name"); } }); } }); }
@OnClick(R.id.save_btn) public void saveUser() { FirebaseUser user = auth.getCurrentUser(); if(user == null) return; UserProfileChangeRequest.Builder userProfileChangeRequest = new UserProfileChangeRequest.Builder(); String userName = name.getText().toString(); if(!userName.equals(auth.getCurrentUser().getDisplayName())) { userProfileChangeRequest.setDisplayName(userName); } int index = providersLayout.getCheckedRadioButtonId(); List<? extends UserInfo> providerData = user.getProviderData(); if(index >= 0 && index < providerData.size()) { Uri uri = providerData.get(index).getPhotoUrl(); if(uri != null && !uri.equals(user.getPhotoUrl())) { userProfileChangeRequest.setPhotoUri(uri); } } progressBar.setVisibility(View.VISIBLE); user.updateProfile(userProfileChangeRequest.build()) .addOnCompleteListener(task -> { progressBar.setVisibility(View.INVISIBLE); if (task.isSuccessful()) { showSnackbar(R.string.profile_updated); } }); }
@ReactMethod public void updateUserProfile(ReadableMap props, final Callback callback) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); UserProfileChangeRequest.Builder profileBuilder = new UserProfileChangeRequest.Builder(); Map<String, Object> m = FirestackUtils.recursivelyDeconstructReadableMap(props); if (m.containsKey("displayName")) { String displayName = (String) m.get("displayName"); profileBuilder.setDisplayName(displayName); } if (m.containsKey("photoUri")) { String photoUriStr = (String) m.get("photoUri"); Uri uri = Uri.parse(photoUriStr); profileBuilder.setPhotoUri(uri); } UserProfileChangeRequest profileUpdates = profileBuilder.build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User profile updated"); FirebaseUser u = FirebaseAuth.getInstance().getCurrentUser(); userCallback(u, callback); } else { // userErrorCallback(task, callback); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception ex) { userExceptionCallback(ex, callback); } }); }
/** * @param user * @param request * @return */ @CheckReturnValue @NonNull public static Completable updateProfile( @NonNull final FirebaseUser user, @NonNull final UserProfileChangeRequest request) { return RxTask.completes(new Callable<Task<Void>>() { @Override public Task<Void> call() throws Exception { return user.updateProfile(request); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_user); username = (EditText) findViewById(R.id.usernameRegistration); pass = (EditText) findViewById(R.id.passwordRegistration); passVerification = (EditText) findViewById(R.id.passwordRegistrationConfirmation); firstname = (EditText) findViewById(R.id.firstName); lastname = (EditText) findViewById(R.id.lastName); setViews(true); progressBar = (ProgressBar) findViewById(R.id.registrationPageProgressBar); 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()); String name = firstname.getText().toString() + " " + lastname.getText().toString(); UserProfileChangeRequest profileChangeRequest = new UserProfileChangeRequest.Builder(). setDisplayName(name).build(); user.updateProfile(profileChangeRequest); DatabaseReference myRef = FirebaseDatabase.getInstance().getReference("users").child(user.getUid()); myRef.child(user.getUid()).push(); // As firebase does not accept keys with empty values, I'm putting a dummy item with empty Strings and -1 as ints // Quantity of items in cart is not realtime database quantity but the quantity the user wants ArrayList<ShoppingItem> cart = new ArrayList<>(); cart.add(new ShoppingItem(-1, "", "", "", -1, -1)); Map<String, Object> cartItems = new HashMap<>(); cartItems.put("cartItems", cart); // Adding a isCartEmpty State Variable for cart window display Map<String, Object> cartState = new HashMap<>(); cartState.put("isCartEmpty", Boolean.TRUE); // Updating the database for the user myRef.updateChildren(cartItems); myRef.updateChildren(cartState); sendVerificationEmail(); } else { // User is signed out Log.d(TAG, "onAuthStateChanged:signed_out"); } } }; mRegister = (Button) findViewById(R.id.registerButton); mRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setViews(false); email = username.getText().toString(); password = pass.getText().toString(); passwordVerification = passVerification.getText().toString(); if (password.equals(passwordVerification) && !password.equals("") && !passwordVerification.equals("")) { createAccount(); } else { Snackbar.make(findViewById(R.id.newUserPage), "Passwords don't match", Snackbar.LENGTH_SHORT).show(); pass.setText(""); passVerification.setText(""); setViews(true); } } }); }
UserUpdateProfileOnSubscribe(FirebaseUser user, UserProfileChangeRequest request) { this.user = user; this.request = request; }
/** * @see FirebaseUser#updateProfile(UserProfileChangeRequest) */ @CheckResult @NonNull public static Completable updateProfile(@NonNull FirebaseUser user, @NonNull UserProfileChangeRequest request) { return Completable.create(new UserUpdateProfileOnSubscribe(user, request)); }
@Test @Config(shadows = {AuthHelperShadow.class}) public void testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials() { // init mocks reset(AuthHelperShadow.getSaveSmartLockInstance(null)); TestHelper.initializeApp(RuntimeEnvironment.application); EmailActivity emailActivity = createActivity(); // Trigger new user UI (bypassing check email) emailActivity.onNewUser( new User.Builder(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL) .setName(TestConstants.NAME) .setPhotoUri(TestConstants.PHOTO_URI) .build()); EditText email = emailActivity.findViewById(R.id.email); EditText name = emailActivity.findViewById(R.id.name); EditText password = emailActivity.findViewById(R.id.password); email.setText(TestConstants.EMAIL); name.setText(TestConstants.NAME); password.setText(TestConstants.PASSWORD); when(AuthHelperShadow.getFirebaseAuth() .createUserWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)) .thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null)); when(AuthHelperShadow.getCurrentUser().updateProfile(any(UserProfileChangeRequest.class))) .thenReturn(new AutoCompleteTask<Void>(null, true, null)); Button button = emailActivity.findViewById(R.id.button_create); button.performClick(); // Verify create user request verify(AuthHelperShadow.getFirebaseAuth()) .createUserWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD); // Finally, the new credential should be saved to SmartLock TestHelper.verifySmartLockSave( EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD); }