Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public ActionResult FireBaseLogin(FormCollection collection)
        {
            string email = collection["email"];
            string uid   = collection["uid"];

            FireBaseUser = new FireBaseUser(email, uid);

            return(View());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
        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));
            }
        }
Exemplo n.º 8
0
        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!");
        }
Exemplo n.º 9
0
        public static async Task <bool> ForgotPassword(FireBaseUser user)
        {
            const string urlEndPoint = "sendOobCode";

            return(await IsValidRequest(user, urlEndPoint));
        }
Exemplo n.º 10
0
        public static async Task <bool> ChangePassword(FireBaseUser user)
        {
            const string urlEndPoint = "update";

            return(await IsValidRequest(user, urlEndPoint, user.NewPassword));
        }
Exemplo n.º 11
0
        public static async Task <bool> LoginSuccessfull(FireBaseUser user)
        {
            const string urlEndPoint = "signInWithPassword";

            return(await IsValidRequest(user, urlEndPoint));
        }