একজন ব্যবহারকারী তৈরি করুন
নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্পগুলো রয়েছে:
আপনার অ্যাপ থেকে : আপনার Firebase প্রজেক্টে
CreateUserWithEmailAndPasswordমেথডটি কল করে অথবা Google Sign-In বা Facebook Login-এর মতো কোনো ফেডারেটেড আইডেন্টিটি প্রোভাইডার ব্যবহার করে প্রথমবারের মতো কোনো ইউজারকে সাইন ইন করিয়ে একজন নতুন ইউজার তৈরি করুন।Firebase কনসোলে : Security > Authentication > Users ট্যাবে একটি নতুন পাসওয়ার্ড-প্রমাণিত ব্যবহারকারী তৈরি করুন।
বর্তমানে সাইন-ইন করা ব্যবহারকারীকে খুঁজুন
বর্তমান ব্যবহারকারীকে পাওয়ার প্রস্তাবিত উপায় হলো 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` রিটার্ন করবে।
ব্যবহারকারীর পরিচয়পত্র সংরক্ষণ করুন
ব্যবহারকারী সাইন ইন করার পর তার ক্রেডেনশিয়ালগুলো লোকাল কীস্টোরে সংরক্ষিত হবে। ব্যবহারকারীকে সাইন আউট করার মাধ্যমে তার ক্রেডেনশিয়ালের লোকাল ক্যাশ মুছে ফেলা যায়। কীস্টোরটি প্ল্যাটফর্ম-নির্দিষ্ট:
- অ্যাপল প্ল্যাটফর্ম: কীচেইন পরিষেবা ।
- অ্যান্ড্রয়েড: অ্যান্ড্রয়েড কীস্টোর ।
- উইন্ডোজ: ক্রেডেনশিয়াল ম্যানেজমেন্ট এপিআই ।
- OS X: কীচেইন পরিষেবা ।
- লিনাক্স: লিবসিক্রেট , যা ব্যবহারকারীকে অবশ্যই ইনস্টল করতে হবে।
একজন ব্যবহারকারীর প্রোফাইল পান
কোনো ব্যবহারকারীর প্রোফাইল তথ্য পেতে, 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 কনসোলের Authentication বিভাগের Email Templates পৃষ্ঠায় ব্যবহৃত ইমেল টেমপ্লেটটি কাস্টমাইজ করতে পারেন। Firebase Help Center-এ Email Templates দেখুন।
ব্যবহারকারীর পাসওয়ার্ড সেট করুন
আপনি 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 কনসোলের Security > Authentication > Templates ট্যাবে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা কাস্টমাইজ করতে পারেন। 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 কনসোলের Security > Authentication > Users ট্যাব থেকে ব্যবহারকারীদের মুছে ফেলতে পারেন।
একজন ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন
কিছু নিরাপত্তামূলক কাজ—যেমন অ্যাকাউন্ট মুছে ফেলা , প্রাথমিক ইমেল ঠিকানা সেট করা এবং পাসওয়ার্ড পরিবর্তন করা —করার জন্য ব্যবহারকারীকে সম্প্রতি সাইন ইন করতে হয়। আপনি যদি এই কাজগুলোর মধ্যে কোনো একটি করেন এবং ব্যবহারকারী অনেক আগে সাইন ইন করে থাকেন, তাহলে কাজটি ব্যর্থ হয়।
যখন এমনটা ঘটে, তখন ব্যবহারকারীর কাছ থেকে নতুন সাইন-ইন ক্রেডেনশিয়াল নিয়ে এবং সেই ক্রেডেনশিয়ালগুলো 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