private async void ShowDialog()
        {
            var result = await((MetroWindow)Application.Current.MainWindow).ShowInputAsync("Input your IP and port", "Example : 1.1.1.1:3000");

            if (result == null || result.Length == 0)
            {
                return;
            }
            LoginDialogData data = await((MetroWindow)Application.Current.MainWindow).ShowLoginAsync("Login", "Your IP is " + (result));

            if (data == null || data.Username == null || data.Password == null)
            {
                return;
            }

            var mSetting = new MetroDialogSettings()
            {
                NegativeButtonText    = "Cancel",
                AnimateShow           = false,
                AnimateHide           = false,
                DialogTitleFontSize   = 20,
                DialogMessageFontSize = 16
            };

            var controller = await((MetroWindow)Application.Current.MainWindow).ShowProgressAsync("Please wait...", "Connecting to the server...", settings: mSetting);

            controller.SetIndeterminate();
            controller.SetCancelable(true);
            ServerBack back = await Utils.NetUtils.LoginAsync(result + "/v1/login", data.Username, data.Password);

            await controller.CloseAsync();

            var conn = new SQLiteAsyncConnection(App.DB_NAME);
            await conn.InsertAsync(new SettingModel
            {
                Token = back.Message,
                URL   = result
            });

            MessageDialogResult msg = await((MetroWindow)Application.Current.MainWindow).ShowMessageAsync("SERVER BACK", back.Message);
        }
Beispiel #2
0
        public static async Task <ServerBack> LoginAsync(string url, string username, string password)
        {
            ServerBack back;

            var data = new LoginModel
            {
                user = new UserModel
                {
                    name     = username,
                    password = password
                }
            };
            string json                = JsonConvert.SerializeObject(data);
            var    content             = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage result = await client.PostAsync(url, content);

            return(back = new ServerBack
            {
                Code = (int)result.StatusCode,
                Message = await result.Content.ReadAsStringAsync()
            });
        }
        private async void resetDefaultSetting(object x)
        {
            var passwordBox = x as PasswordBox;

            Password      = passwordBox.Password;
            IsSettingOpen = false;
            var mSetting = new MetroDialogSettings()
            {
                NegativeButtonText    = "Cancel",
                AnimateShow           = false,
                AnimateHide           = false,
                DialogTitleFontSize   = 20,
                DialogMessageFontSize = 16
            };
            var controller = await((MetroWindow)System.Windows.Application.Current.MainWindow).ShowProgressAsync("Please wait...", "Connecting to the server...", settings: mSetting);

            controller.SetIndeterminate();
            controller.SetCancelable(true);
            ServerBack back = await Utils.NetUtils.LoginAsync(Url + "/v1/login", Username, Password);

            await controller.CloseAsync();

            var conn = new SQLiteAsyncConnection(App.DB_NAME);
            await conn.ExecuteAsync("Delete from SettingModel");

            await conn.InsertAsync(new SettingModel
            {
                Token = back.Message,
                URL   = Url
            });

            App.TOKEN = back.Message;

            controller = await((MetroWindow)System.Windows.Application.Current.MainWindow).ShowProgressAsync("Please wait...", "Refreshing", settings: mSetting);
            controller.SetIndeterminate();
            controller.SetCancelable(false);
            initData();
            await controller.CloseAsync();
        }