private static async Task <bool> IsValidRequest(FireBaseUser user, string endPoint, string newPassword = null) { using (HttpClient client = new HttpClient()) { StringContent content = SetContent(user, newPassword); HttpResponseMessage response = await GetResponse(client, content, endPoint); if (response == null) { return(false); } if (response.IsSuccessStatusCode) { var fireBaseUser = await GetUserIds(response); user.Id = fireBaseUser.Id; user.IdToken = fireBaseUser.IdToken; return(true); } else { DisplayError(response); } return(false); } }
private void Button_Log_In_Click(object sender, RoutedEventArgs e) { /*if (string.IsNullOrEmpty(uploadPath) || string.IsNullOrEmpty(downloadPath)) * { * MessageBox.Show("Please choose upload and download folders"); * return; * } * string IPAdress = ConfigurationManager.ConnectionStrings[USER_IP].ToString(); * bool is_succeed = await _proxy.Login(this.User_Name.Text, this.User_Password.Password, IPAdress,connection_string); * if (!is_succeed) return;*/ #region Condition if (string.IsNullOrWhiteSpace(this.User_Name.Text) || string.IsNullOrWhiteSpace(this.User_Password.Password)) { MessageBox.Show("Please fill all the fields"); return; } #endregion FirebaseResponse res = client.Get(@"User/" + User_Name.Text); FireBaseUser ResUser = res.ResultAs <FireBaseUser>(); // dataBase Result FireBaseUser CurUser = new FireBaseUser() { UserName = User_Name.Text, Password = User_Password.Password }; if (ResUser.Equals(CurUser)) { FileTransfer sign_up_window = new FileTransfer(downloadPath, uploadPath, _proxy); this.Close(); } }
public ActionResult FireBaseLogin(FormCollection collection) { string email = collection["email"]; string uid = collection["uid"]; FireBaseUser = new FireBaseUser(email, uid); return(View()); }
private static async Task <FireBaseUser> GetUserIds(HttpResponseMessage response) { var user = new FireBaseUser(); string resultJson = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <FirebaseResult>(resultJson); user.Id = result.LocalId; user.IdToken = result.IdToken; return(user); }
private static bool BothPasswordsMatch(FireBaseUser user) { if (user.Password.Trim() != user.Password2.Trim()) { MessageBox.Show("Your Passwords Don't Match!", "Password Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } else { return(true); } }
public static async Task <bool> RegistrationSuccessfull(FireBaseUser user) { if (BothPasswordsMatch(user)) { const string urlEndPoint = "signUp"; if (await IsValidRequest(user, urlEndPoint)) { var userRepository = new UserRepository(); userRepository.AddUser(user); return(true); } } return(false); }
private static StringContent SetContent(FireBaseUser user, string newPassword = null) { var body = new { email = user.Email, idToken = user.IdToken, password = (newPassword == null) ? user.Password : newPassword, returnSecureToken = (newPassword == null) ? true : false, }; var forgotPWBody = new { requestType = "PASSWORD_RESET", email = user.Email }; if (string.IsNullOrWhiteSpace(user.Password)) { return(SerializeBody(forgotPWBody)); } else { return(SerializeBody(body)); } }
private void Button_SignUp_Click(object sender, RoutedEventArgs e) { #region Condition if (string.IsNullOrWhiteSpace(txt_User_FullName.Text) || string.IsNullOrWhiteSpace(txt_User_Password.Password) || string.IsNullOrWhiteSpace(txt_User_Gender.Text) || string.IsNullOrWhiteSpace(txt_User_FullName.Text) || string.IsNullOrWhiteSpace(txt_User_Nic_Number.Text)) { MessageBox.Show("Please fill all the fields"); return; } #endregion FireBaseUser user = new FireBaseUser(txt_User_FullName.Text, txt_User_Password.Password, txt_User_FullName.Text, txt_User_Gender.Text, txt_User_Nic_Number.Text); SetResponse set = client.Set(@"User/" + txt_User_FullName.Text, user); MessageBox.Show("Successfully registered!"); }
public static async Task <bool> ForgotPassword(FireBaseUser user) { const string urlEndPoint = "sendOobCode"; return(await IsValidRequest(user, urlEndPoint)); }
public static async Task <bool> ChangePassword(FireBaseUser user) { const string urlEndPoint = "update"; return(await IsValidRequest(user, urlEndPoint, user.NewPassword)); }
public static async Task <bool> LoginSuccessfull(FireBaseUser user) { const string urlEndPoint = "signInWithPassword"; return(await IsValidRequest(user, urlEndPoint)); }