com.google.firebase.auth.UserProfileChangeRequest Java Examples

The following examples show how to use com.google.firebase.auth.UserProfileChangeRequest. 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 6 votes vote down vote up
public 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]
}
 
Example #2
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
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();
                }
            }
        });
    }

}
 
Example #3
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
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();
            }
        });
    }
}
 
Example #4
Source File: EditProfile.java    From Shipr-Community-Android with GNU General Public License v3.0 5 votes vote down vote up
private void clearPic() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
            .setPhotoUri(null)
            .build();

}
 
Example #5
Source File: ChatAuthentication.java    From chat21-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private void updateUserProfile(final String displayName, Uri userPhotoUri) {
    Log.d(DEBUG_LOGIN, "updateUserProfile: displayName == " + displayName
            + ", userPhotoUri == " + userPhotoUri);

    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (StringUtils.isValid(displayName)) {
        UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder()
                .setDisplayName(displayName);

        if (userPhotoUri != null)
            builder.setPhotoUri(userPhotoUri);

        UserProfileChangeRequest profileUpdates = builder.build();

        user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                Log.d(DEBUG_LOGIN, "updateUserProfile.onCompleteSuccess");

                if (task.isSuccessful()) {
                    Log.i(DEBUG_LOGIN, "User profile (" + displayName + ")" +
                            " updated with success for user with uid: " + user.getUid());
                    isUserProfileUpdated = true;
                } else {
                    task.getException().printStackTrace();

                    String errorMessage = "updateUserProfile.onCompleteError: "
                            + task.getException().getMessage();
                    Log.e(DEBUG_LOGIN, errorMessage);
                    FirebaseCrash.report(new Exception(errorMessage));
                }
            }
        });
    }
}
 
Example #6
Source File: RxFirebaseUser.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Observable<Void> updateProfile(@NonNull final FirebaseUser firebaseUser,
                                             @NonNull final UserProfileChangeRequest request) {
    return Observable.unsafeCreate(new Observable.OnSubscribe<Void>() {
        @Override
        public void call(final Subscriber<? super Void> subscriber) {
            RxTask.assignOnTask(subscriber, firebaseUser.updateProfile(request));
        }
    });
}
 
Example #7
Source File: NewSimplicityAccount.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private void saveUserInfo(){
    try{
        String displayName = Objects.requireNonNull(editText0.getText()).toString();
        if(editText0.getText().toString().isEmpty()){
            editText0.setError("Name required");
            editText0.requestFocus();
            return;
        }

        if(currentUser != null && pic_url!= null){
            UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
                    .setDisplayName(displayName)
                    .setPhotoUri(Uri.parse(pic_url))
                    .build();
            currentUser.updateProfile(userProfileChangeRequest)

                    .addOnCompleteListener(task -> {
                        if(task.isSuccessful()){
                            Cardbar.snackBar(getApplicationContext(), "Simplicity account created!", true).show();
                            finish();
                        }
                    });
        }
    }catch (NullPointerException i){
        i.printStackTrace();
    }catch (Exception ignored){

    }
}
 
Example #8
Source File: SimplicityProfile.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private void saveUserInfo(){
    try{
        if(editText.getText().toString().isEmpty()){
            editText.setError("Name required");
            editText.requestFocus();
            return;
        }

        if(currentUser != null && pic_url!= null){
            UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
                    .setDisplayName(editText.getText().toString())
                    .setPhotoUri(Uri.parse(pic_url))
                    .build();
            currentUser.updateProfile(userProfileChangeRequest)

                    .addOnCompleteListener(task -> {
                        if(task.isSuccessful()){
                            Cardbar.snackBar(SimplicityProfile.this,"Profile updated!", false).show();
                            finish();
                        }
                    });
        }
    }catch (NullPointerException i){
        i.printStackTrace();
    }catch (Exception ignored){

    }
}
 
Example #9
Source File: FirestackAuth.java    From react-native-firestack with MIT License 5 votes vote down vote up
@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);
          }
        });
}
 
Example #10
Source File: RxFirebaseUser.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
        }
    });
}
 
Example #11
Source File: newUser.java    From NITKart with MIT License 4 votes vote down vote up
@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);

        isSeller = getIntent().getExtras().getBoolean("seller");
        if(isSeller){
            ((TextView) findViewById(R.id.userRegistrationPageTitle)).setText("Seller Registration");
        }

        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;

                    if (!isSeller){
                        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));
                        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);
                    } else {
                        myRef = FirebaseDatabase.getInstance().getReference("sellers").child(user.getUid());
                        myRef.child(user.getUid()).push();

//                        Dummy product sold by any seller who has 0 products
                        ArrayList<ShoppingItem> prods = new ArrayList<>();
                        prods.add(new ShoppingItem("", "", "", "", -1, -1));
                        Map<String, Object> prodslist = new HashMap<>();
                        prodslist.put("products", prods);

                        Map<String, Object> state = new HashMap<>();
                        state.put("isEmpty", Boolean.TRUE);

                        // Updating the database for the seller
                        myRef.updateChildren(prodslist);
                        myRef.updateChildren(state);
                    }

                    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);
                }
            }
        });
    }