Firebase में उपयोगकर्ताओं को मैनेज करें

उपयोगकर्ता बनाएं

आप CreateUserWithEmailAndPassword करने का तरीका इस्तेमाल करें या फ़ेडरेटेड आइडेंटिटी का इस्तेमाल करके पहली बार साइन इन करें जैसे, Google साइन-इन या Facebook में लॉगिन करें.

पुष्टि करने की सुविधा से, पासवर्ड की पुष्टि करने वाले नए उपयोगकर्ता भी बनाए जा सकते हैं उपयोगकर्ता पेज पर Firebase कंसोल का सेक्शन देखें.

वर्तमान में प्रवेश किए हुए उपयोगकर्ता को पाएं

वर्तमान उपयोगकर्ता प्राप्त करने का सुझाया गया तरीका यह है कि पुष्टि करने के लिए ऑब्जेक्ट:

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

लिसनर का इस्तेमाल करके, आप यह पक्का करते हैं कि अनुमति देने वाला ऑब्जेक्ट, इंटरमीडिएट में नहीं है स्थिति—जैसे कि शुरू करना—जब आपको मौजूदा उपयोगकर्ता मिल जाए.

जिस उपयोगकर्ता ने साइन-इन किया हुआ है उसकी जानकारी पाने के लिए, 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 तरीके का इस्तेमाल करके. उदाहरण के लिए:

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 प्रोजेक्ट में इंपोर्ट कर सकते हैं. इसके लिए Firebase सीएलआई की auth:import कमांड. उदाहरण के लिए:

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