void FetchUserInfo(string userid) { DatabaseReference reference = Database.DefaultInstance.GetRootReference().GetChild("users/" + userid); reference.ObserveSingleEvent(DataEventType.Value, (DataSnapshot snapshot) => { if (snapshot.GetValue <NSObject>() != NSNull.Null) { string email, fullname, phone; if (snapshot.GetChildSnapshot("email").GetValue <NSObject>() != NSNull.Null) { email = snapshot.GetChildSnapshot("email").GetValue <NSObject>().ToString(); fullname = snapshot.GetChildSnapshot("fullname").GetValue <NSObject>().ToString(); phone = snapshot.GetChildSnapshot("phone").GetValue <NSObject>().ToString(); // Save User info Locally var userDefaults = NSUserDefaults.StandardUserDefaults; userDefaults.SetString(phone, "phone"); userDefaults.SetString(fullname, "fullname"); userDefaults.SetString(email, "email"); userDefaults.SetString(userid, "user_id"); HideProgressBar(); MainViewController mainViewController = this.Storyboard.InstantiateViewController("MainViewController") as MainViewController; mainViewController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(mainViewController, true, null); } } }); }
private void RegisterButton_TouchUpInside(object sender, EventArgs e) { string fullname, phone, email, password; fullname = fulNameText.Text; phone = phoneText.Text; email = emailText.Text; password = passwordText.Text; if (fullname.Length < 5) { var alert = UIAlertController.Create("Alert", "Please enter a valid name", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } else if (phone.Length < 8) { var alert = UIAlertController.Create("Alert", "Please enter a valid Phone Number", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } else if (!email.Contains("@")) { var alert = UIAlertController.Create("Alert", "Please enter a valid email address", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } else if (password.Length < 8) { var alert = UIAlertController.Create("Alert", "Please enter a password upto 8 characters", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } ShowProgressBar("Regsitering you..."); Auth.DefaultInstance.CreateUser(email, password, (AuthDataResult authresult, NSError error) => { if (error == null) { var user = authresult.User; if (user != null) { var userDictionary = new NSDictionary ( "fullname", fullname, "email", email, "phone", phone ); //Save user details to firebase database DatabaseReference userRef = Database.DefaultInstance.GetRootReference().GetChild("users/" + authresult.User.Uid); userRef.SetValue <NSDictionary>(userDictionary); // Save User info Locally var userDefaults = NSUserDefaults.StandardUserDefaults; userDefaults.SetString(phone, "phone"); userDefaults.SetString(fullname, "fullname"); userDefaults.SetString(email, "email"); userDefaults.SetString(authresult.User.Uid, "user_id"); HideProgressBar(); MainViewController mainViewController = this.Storyboard.InstantiateViewController("MainViewController") as MainViewController; mainViewController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(mainViewController, true, null); } } else { HideProgressBar(); var alert = UIAlertController.Create("Error", error.LocalizedDescription, UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } }); }