Пример #1
0
        //Method Post use to block/unblock one account
        public static async Task <bool> PostBlock(AccountBlock request, string title)
        {
            string url = "/api/account/" + title;

            try
            {
                HttpClient client = new HttpClient();

                client = RestAPI.Get_HttpClient_Token();



                var response = new HttpResponseMessage();

                response = await client.PostAsJsonAsync(url, request).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #2
0
        private async Task LoadAccounts()
        {
            accounts = await AccountStorage.Instance.GetAllAsync();

            long     currentTicks  = TOTPUtilities.RemainingTicks;
            TimeSpan remainingTime = new TimeSpan(TOTPUtilities.RemainingTicks);

            accountBlocks = new ObservableCollection <AccountBlock>();
            mappings      = new Dictionary <Account, AccountBlock>();

            foreach (Account account in accounts)
            {
                AccountBlock code = new AccountBlock(account, mainPage);
                code.DeleteRequested += Code_DeleteRequested;
                code.CopyRequested   += Code_CopyRequested;
                code.Removed         += Code_Removed;
                code.Modified        += Code_Modified;

                accountBlocks.Add(code);
                mappings.Add(account, code);
            }

            accountBlocks.CollectionChanged += AccountBlocks_CollectionChanged;
            Codes.ItemsSource = accountBlocks;

            CheckEntries();
        }
Пример #3
0
        private void Code_Removed(object sender, EventArgs e)
        {
            OpenUndo.Begin();

            AccountBlock accountBlock = sender as AccountBlock;

            removedAccountBlock = accountBlock;
            removedIndex        = accountBlocks.IndexOf(accountBlock);

            if (accountBlock != null)
            {
                accountBlocks.Remove(accountBlock);
            }

            CheckEntries();

            undoTimer.Start();
        }
Пример #4
0
        private async void btn_block_Click(object sender, RoutedEventArgs e)
        {
            progress_bar.Visibility = Visibility.Visible;

            Button button = sender as Button;

            User_DTO user = button.DataContext as User_DTO;

            AccountBlock temp = new AccountBlock();

            temp.account_id = user.account_id;

            bool result = false;

            if (user.is_block)
            {
                result = await RestAPI.PostBlock(temp, "unlock");
            }
            else
            {
                result = await RestAPI.PostBlock(temp, "lock");
            }

            if (send != null)
            {
                send.Invoke();
            }

            progress_bar.Visibility = Visibility.Collapsed;
            if (result)
            {
                MessageBox.Show("Successful");
            }
            else
            {
                MessageBox.Show("Fail");
            }
        }
Пример #5
0
        private async void Save_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            Synchronize.StartAnimationAndDisable();
            SetButtonState(false);

            AccountBlockPanel.Visibility = Visibility.Collapsed;

            MainPage.ClearBanners();
            AccountBlockPanel.Children.Clear();

            bool valid = true;

            if (string.IsNullOrWhiteSpace(AccountService.Text) || string.IsNullOrWhiteSpace(AccountUsername.Text) || string.IsNullOrWhiteSpace(AccountCode.Text))
            {
                MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("BannerEmptyFields"), true));

                valid = false;
            }

            if (valid)
            {
                try
                {
                    string code = new string(Array.FindAll(AccountCode.Text.ToCharArray(), (c => (char.IsLetterOrDigit(c)))));

                    if (!code.All(char.IsLetterOrDigit))
                    {
                        MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("BannerInvalidCharacters"), true));

                        valid = false;
                    }

                    if (valid)
                    {
                        OTP otp = new OTP(code);

                        Account account = new Account(AccountUsername.Text, code, AccountService.Text);

                        await AccountStorage.Instance.SaveAsync(account);

                        accountBlock = new AccountBlock(account, true, mainPage);
                        accountBlock.CopyRequested += AccountBlock_CopyRequested;

                        MainPage.AddBanner(new Banner(BannerType.Success, ResourceLoader.GetForCurrentView().GetString("BannerSaved"), true));
                        AccountBlockPanel.Children.Add(accountBlock);

                        AccountBlockPanel.Visibility = Visibility.Visible;

                        AccountService.Text  = "";
                        AccountUsername.Text = "";
                        AccountCode.Text     = "";
                    }
                }
                catch (ArgumentException)
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("BannerInvalidCharacters"), true));
                }
                catch (DuplicateAccountException)
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("BannerDuplicateAccount"), true));
                }
                catch (NetworkException)
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("NoInternetConnection"), true));
                }
                catch (Exception)
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("BannerUnknownError"), true));
                }
            }

            SetButtonState(true);
            Synchronize.StopAnimationAndEnable();
            Synchronize.IsEnabled = false;
        }