示例#1
0
        private void LoginWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string Username = null, Password = null;

            Dispatcher.Invoke(() =>
            {
                Username = UsernameBox.Text;
                Password = PasswordBox.Password;
            });

            WebInterface.VerifyWebsite(this);

            if (!Login(Username, Password))
            {
                return;
            }
            var Result = WebInterface.Change(DataInterface.Read <string>("token"));

            switch (Result)
            {
            case WebInterface.ChangeResult.OK:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "You have successfully logged into your Synapse account!\n\nYou can now restart Synapse X to use the software.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Information);
                    });
                Environment.Exit(0);
                return;
            }

            case WebInterface.ChangeResult.INVALID_TOKEN:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "Invalid token. Please contact 3dsboy08 on Discord.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                        LoginButton.Content = "Login";
                        LoggingIn           = false;
                    });
                return;
            }

            case WebInterface.ChangeResult.EXPIRED_TOKEN:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "Expired token. Please contact 3dsboy08 on Discord.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                        LoginButton.Content = "Login";
                        LoggingIn           = false;
                    });
                return;
            }

            case WebInterface.ChangeResult.ALREADY_EXISTING_HWID:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "You already have a Synapse account! Please log into the account you have already created.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                        LoginButton.Content = "Login";
                        LoggingIn           = false;
                    });
                return;
            }

            case WebInterface.ChangeResult.NOT_ENOUGH_TIME:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "You have changed your whitelist too recently. Please wait 24 hours from your last whitelist change and try again.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                        Environment.Exit(0);
                    });
                return;
            }

            case WebInterface.ChangeResult.INVALID_REQUEST:
            case WebInterface.ChangeResult.UNKNOWN:
            {
                Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(
                            "Failed to change whitelist to Synapse account. Please contact 3dsboy08 on Discord.",
                            "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                        LoginButton.Content = "Login";
                        LoggingIn           = false;
                    });
                return;
            }
            }
        }