Firebase-এ ব্যবহারকারীদের ম্যানেজ করা

ব্যবহারকারী তৈরি করা

নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্প আছে:

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

  • 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 পদ্ধতি false রিটার্ন করবে।

ব্যবহারকারীর ক্রেডেনশিয়াল সেভ করে রাখা

ব্যবহারকারী সাইন-ইন করার পরে, ব্যবহারকারীর ক্রেডেনশিয়াল স্থানীয় কীস্টোরে সেভ করা হবে। ব্যবহারকারীকে সাইন-আউট করে ব্যবহারকারীর ক্রেডেনশিয়ালের লোকাল ক্যাশে মুছে দেওয়া যায়। কীস্টোর প্ল্যাটফর্ম নির্দিষ্ট:

ব্যবহারকারীর প্রোফাইল পাওয়া

ব্যবহারকারীর প্রোফাইল সংক্রান্ত তথ্য পেতে, 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