Firebase-এ ব্যবহারকারীদের পরিচালনা করুন

একটি ব্যবহারকারী তৈরি করুন

আপনি CreateUserWithEmailAndPassword পদ্ধতিতে কল করার মাধ্যমে অথবা Google সাইন-ইন বা Facebook লগইন- এর মতো ফেডারেটেড আইডেন্টিটি প্রদানকারী ব্যবহার করে প্রথমবার একজন ব্যবহারকারীকে সাইন ইন করার মাধ্যমে আপনার Firebase প্রকল্পে একজন নতুন ব্যবহারকারী তৈরি করুন।

এছাড়াও আপনি ব্যবহারকারী পৃষ্ঠায় Firebase কনসোলের প্রমাণীকরণ বিভাগ থেকে নতুন পাসওয়ার্ড-প্রমাণিত ব্যবহারকারী তৈরি করতে পারেন।

বর্তমানে সাইন ইন করা ব্যবহারকারী পান

বর্তমান ব্যবহারকারীকে পাওয়ার প্রস্তাবিত উপায় হল Auth অবজেক্টে একজন শ্রোতা সেট করে:

class MyAuthStateListener : public firebase::auth::AuthStateListener {
 public:
  void OnAuthStateChanged(firebase::auth::Auth* auth) override {
    firebase::auth::User user = auth->current_user();
    if (user.is_valid()) {
      // User is signed in
      printf("OnAuthStateChanged: signed_in %s\n", user.uid().c_str());
    } else {
      // User is signed out
      printf("OnAuthStateChanged: signed_out\n");
    }
    // ...
  }
};
// ... initialization code
// Test notification on registration.
MyAuthStateListener state_change_listener;
auth->AddAuthStateListener(&state_change_listener);

একজন শ্রোতা ব্যবহার করে, আপনি নিশ্চিত করেন যে Auth অবজেক্টটি একটি মধ্যবর্তী অবস্থায় নেই—যেমন আরম্ভ করা—যখন আপনি বর্তমান ব্যবহারকারী পাবেন।

এছাড়াও আপনি current_user এ কল করে বর্তমানে সাইন ইন করা ব্যবহারকারীকে পেতে পারেন। যদি একজন ব্যবহারকারী সাইন ইন না করে থাকেন, তাহলে ব্যবহারকারীর is_valid পদ্ধতি মিথ্যা হয়ে যাবে।

ব্যবহারকারীর শংসাপত্র বজায় রাখুন

ব্যবহারকারী সাইন ইন করার পরে ব্যবহারকারীর শংসাপত্রগুলি স্থানীয় কীস্টোরে সংরক্ষণ করা হবে৷ ব্যবহারকারীকে সাইন আউট করার মাধ্যমে ব্যবহারকারীর শংসাপত্রের স্থানীয় ক্যাশে মুছে ফেলা যেতে পারে৷ কীস্টোরটি প্ল্যাটফর্ম নির্দিষ্ট:

একটি ব্যবহারকারীর প্রোফাইল পান

একজন ব্যবহারকারীর প্রোফাইল তথ্য পেতে, firebase::auth::User এর একটি উদাহরণের অ্যাক্সেসর পদ্ধতি ব্যবহার করুন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  std::string name = user.display_name();
  std::string email = user.email();
  std::string photo_url = user.photo_url();
  // 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 firebase::auth::User::Token() instead.
  std::string uid = user.uid();
}

ব্যবহারকারীর প্রদানকারী-নির্দিষ্ট প্রোফাইল তথ্য পান

ব্যবহারকারীর সাথে লিঙ্ক করা সাইন-ইন প্রদানকারীদের থেকে প্রোফাইল তথ্য পুনরুদ্ধার করতে, ProviderData পদ্ধতি ব্যবহার করুন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  for (auto it = user.provider_data().begin();
       it != user.provider_data().end(); ++it) {
    firebase::auth::UserInfoInterface profile = *it;
    // Id of the provider (ex: google.com)
    std::string providerId = profile.provider_id();

    // UID specific to the provider
    std::string uid = profile.uid();

    // Name, email address, and profile photo Url
    std::string name = profile.display_name();
    std::string email = profile.email();
    std::string photoUrl = profile.photo_url();
  }
}

একজন ব্যবহারকারীর প্রোফাইল আপডেট করুন

আপনি UpdateUserProfile পদ্ধতির মাধ্যমে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য-ব্যবহারকারীর প্রদর্শন নাম এবং প্রোফাইল ফটো URL-কে আপডেট করতে পারেন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  firebase::auth::User::UserProfile profile;
  profile.display_name = "Jane Q. User";
  profile.photo_url = "https://example.com/jane-q-user/profile.jpg";
  user.UpdateUserProfile(profile).OnCompletion(
      [](const firebase::Future<void>& completed_future, void* user_data) {
        // We are probably in a different thread right now.
        if (completed_future.error() == 0) {
          printf("User profile updated.");
        }
      },
      nullptr);  // pass user_data here.
}

একটি ব্যবহারকারীর ইমেল ঠিকানা সেট করুন

আপনি UpdateEmail পদ্ধতির মাধ্যমে ব্যবহারকারীর ইমেল ঠিকানা সেট করতে পারেন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  user.UpdateEmail("user@example.com")
      .OnCompletion(
          [](const firebase::Future<void>& completed_future,
             void* user_data) {
            // We are probably in a different thread right now.
            if (completed_future.error() == 0) {
              printf("User email address updated.");
            }
          },
          nullptr);
}

একজন ব্যবহারকারীকে একটি যাচাইকরণ ইমেল পাঠান

আপনি SendEmailVerification পদ্ধতির মাধ্যমে একজন ব্যবহারকারীকে একটি ঠিকানা যাচাইকরণ ইমেল পাঠাতে পারেন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  user.SendEmailVerification().OnCompletion(
      [](const firebase::Future<void>& completed_future, void* user_data) {
        // We are probably in a different thread right now.
        if (completed_future.error() == 0) {
          printf("Email sent.");
        }
      },
      nullptr);
}

আপনি Firebase কনসোলের প্রমাণীকরণ বিভাগে ব্যবহৃত ইমেল টেমপ্লেটটি কাস্টমাইজ করতে পারেন, ইমেল টেমপ্লেট পৃষ্ঠায়। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।

ব্যবহারকারীর পাসওয়ার্ড সেট করুন

আপনি UpdatePassword পদ্ধতিতে ব্যবহারকারীর পাসওয়ার্ড সেট করতে পারেন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
std::string newPassword = "SOME-SECURE-PASSWORD";

if (user.is_valid()) {
  user.UpdatePassword(newPassword.c_str())
      .OnCompletion(
          [](const firebase::Future<void>& completed_future,
             void* user_data) {
            // We are probably in a different thread right now.
            if (completed_future.error() == 0) {
              printf("password updated.");
            }
          },
          nullptr);
}

একটি পাসওয়ার্ড রিসেট ইমেল পাঠান

আপনি SendPasswordResetEmail পদ্ধতির মাধ্যমে একজন ব্যবহারকারীকে একটি পাসওয়ার্ড রিসেট ইমেল পাঠাতে পারেন। উদাহরণ স্বরূপ:

std::string emailAddress = "user@example.com";

auth->SendPasswordResetEmail(emailAddress.c_str())
    .OnCompletion(
        [](const firebase::Future<void>& completed_future,
           void* user_data) {
          // We are probably in a different thread right now.
          if (completed_future.error() == 0) {
            // Email sent.
          } else {
            // An error happened.
            printf("Error %d: %s", completed_future.error(),
                   completed_future.error_message());
          }
        },
        nullptr);

আপনি Firebase কনসোলের প্রমাণীকরণ বিভাগে ব্যবহৃত ইমেল টেমপ্লেটটি কাস্টমাইজ করতে পারেন, ইমেল টেমপ্লেট পৃষ্ঠায়। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।

এছাড়াও আপনি Firebase কনসোল থেকে পাসওয়ার্ড রিসেট ইমেল পাঠাতে পারেন।

একটি ব্যবহারকারী মুছুন

আপনি Delete পদ্ধতির মাধ্যমে একটি ব্যবহারকারী অ্যাকাউন্ট মুছে ফেলতে পারেন। উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
  user.Delete().OnCompletion(
      [](const firebase::Future<void>& completed_future, void* user_data) {
        if (completed_future.error() == 0) {
          // User deleted.
        } else {
          // An error happened.
          printf("Error %d: %s", completed_future.error(),
                 completed_future.error_message());
        }
      },
      nullptr);
}

এছাড়াও আপনি ব্যবহারকারীদের পৃষ্ঠায় Firebase কনসোলের প্রমাণীকরণ বিভাগ থেকে ব্যবহারকারীদের মুছতে পারেন।

একজন ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন

কিছু নিরাপত্তা-সংবেদনশীল ক্রিয়া- যেমন একটি অ্যাকাউন্ট মুছে ফেলা , একটি প্রাথমিক ইমেল ঠিকানা সেট করা , এবং একটি পাসওয়ার্ড পরিবর্তন করা - এর জন্য প্রয়োজন যে ব্যবহারকারী সম্প্রতি সাইন ইন করেছেন। আপনি যদি এই ক্রিয়াগুলির মধ্যে একটি করেন এবং ব্যবহারকারী অনেক আগে সাইন ইন করেন, তাহলে কর্ম ব্যর্থ হয়

যখন এটি ঘটবে, ব্যবহারকারীর কাছ থেকে নতুন সাইন-ইন শংসাপত্র পেয়ে ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন এবং প্রমাণপত্রগুলিকে Reauthenticate করুন৷ উদাহরণ স্বরূপ:

firebase::auth::User user = auth->current_user();

// Get auth credentials from the user for re-authentication. The example
// below shows email and password credentials but there are multiple
// possible providers, such as GoogleAuthProvider or FacebookAuthProvider.
firebase::auth::Credential credential =
    firebase::auth::EmailAuthProvider::GetCredential("user@example.com",
                                                     "password1234");

if (user.is_valid()) {
  user.Reauthenticate(credential)
      .OnCompletion(
          [](const firebase::Future<void>& completed_future,
             void* user_data) {
            if (completed_future.error() == 0) {
              printf("User re-authenticated.");
            }
          },
          nullptr);
}

ব্যবহারকারীর অ্যাকাউন্ট আমদানি করুন

আপনি Firebase CLI এর auth:import কমান্ড ব্যবহার করে আপনার Firebase প্রকল্পে একটি ফাইল থেকে ব্যবহারকারীর অ্যাকাউন্ট আমদানি করতে পারেন। উদাহরণ স্বরূপ:

firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14