Ejemplo n.º 1
0
        private async void LogIn(object sender, RoutedEventArgs e)
        {
            loginButton.IsEnabled   = false;
            ProgressRing.Visibility = Visibility.Visible;
            ProgressRing.IsActive   = true;
            LoginText.Visibility    = Visibility.Collapsed;

            if (NormalAuth.Visibility == Visibility.Visible)
            {
                //NORMAL AUTHENTICATION
                LoginResult result   = new LoginResult();
                var         username = Username.Text;
                var         password = Password.Password;
                await Task.Run(async() =>
                {
                    result = await RESTCalls.Login(username, password);
                    if (result.exception != null)
                    {
                        LoginResult cache = result;
                        result            = JsonConvert.DeserializeObject <LoginResult>(((ApiException)result.exception).Content);
                        result.exception  = cache.exception;
                    }
                });

                if (result.CaptchaKey != null)
                {
                    CaptchaView.Visibility = Visibility.Visible;
                    CaptchaView.Navigate(new Uri("https://discordapp.com/login"));
                    cusername = username;
                    cpassword = password;
                    MessageDialog md = new MessageDialog("Login in Failed, try again here", "Discord thinks you're a bot!");
                    await md.ShowAsync();
                }
                else if (result.Email != null || result.Password != null)
                {
                    if (result.Email != null)
                    {
                        EmailErrorText.Text = "";
                        for (int i = 0; i < result.Email.Count; i++)
                        {
                            EmailErrorText.Text += result.Email[i];
                            if (i != result.Email.Count - 1)
                            {
                                EmailErrorText.Text += Environment.NewLine;
                            }
                        }

                        EmailErrorText.Visibility = Visibility.Visible;
                    }
                    if (result.Password != null)
                    {
                        PasswordErrorText.Text = "";
                        for (int i = 0; i < result.Password.Count; i++)
                        {
                            PasswordErrorText.Text += result.Password[i];
                            if (i != result.Password.Count - 1)
                            {
                                PasswordErrorText.Text += Environment.NewLine;
                            }
                        }

                        PasswordErrorText.Visibility = Visibility.Visible;
                    }
                }
                else if (result.exception != null)
                {
                    string ermsg = "";
                    switch (result.exception.Message)
                    {
                    case "Response status code does not indicate success: 400 ().":
                    case "Response status code does not indicate success: 400().":
                        ermsg = "Response code (from Discord Servers) indicates failure (400), please check your email for an email from Discord to verify your IP";
                        break;

                    case "TBD":
                        ermsg = "A bug in the code is preventing log in, some imported code (refit) isn't working, trying again later may work";
                        break;

                    case "ILoginService doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project.":
                        ermsg = "A bug in the code is preventing log in. Some imported code (Refit) isn't working as expected";
                        break;

                    default:
                        ermsg = "Unknown error, maybe try again later";
                        break;
                    }
                    MessageDialog msg = new MessageDialog(ermsg);
                    await msg.ShowAsync();
                }

                else if (result.MFA == true)
                {
                    mfaTicket               = result.Ticket;
                    NormalAuth.Visibility   = Visibility.Collapsed;
                    MFAuth.Visibility       = Visibility.Visible;
                    loginButton.IsEnabled   = true;
                    ProgressRing.Visibility = Visibility.Collapsed;
                    ProgressRing.IsActive   = false;
                    LoginText.Visibility    = Visibility.Visible;
                    if (result.SmsSupported)
                    {
                        MFAsms.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        MFAsms.Visibility = Visibility.Collapsed;
                    }
                }
                else if (result.Token != null)
                {
                    App.LogIn();
                    App.SubpageClosed();
                }
            }
            else if (MFAuth.Visibility == Visibility.Visible)
            {
                //2FA AUTHENTICATION
                API.Login.Models.LoginResult result = new API.Login.Models.LoginResult();
                var mfapass = MFAPassword.Password;
                await Task.Run(async() =>
                {
                    if (sms)
                    {
                        result = await RESTCalls.LoginSMS(mfapass, mfaTicket);
                    }
                    else
                    {
                        result = await RESTCalls.LoginMFA(mfapass, mfaTicket);
                    }
                });

                if (result.exception != null)
                {
                    string ermsg = "";
                    switch (result.exception.Message)
                    {
                    case "Response status code does not indicate success: 400().":
                        ermsg = "Response code (from Discord Servers) indicates failure (400), please check your email and password";
                        break;

                    case "TBD":
                        ermsg = "A bug in the code is preventing log in, some imported code (refit) isn't working, trying again later may work";
                        break;

                    case "ILoginService doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project.":
                        ermsg = "A bug in the code is preventing log in. Some imported code (Refit) isn't working as expected";
                        break;

                    default:
                        ermsg = "Unknown error, maybe try again later";
                        break;
                    }
                    MessageDialog msg = new MessageDialog(ermsg);
                    await msg.ShowAsync();
                }
                else if (result.Token != null)
                {
                    App.LogIn();
                    App.SubpageClosed();
                }
            }
            else if (TokenAuth.Visibility == Visibility.Visible)
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Token.Password);
                    var resp = await client.GetAsync("https://discordapp.com/api/v6/users/@me");

                    if (resp.IsSuccessStatusCode)
                    {
                        PasswordCredential credentials = new PasswordCredential("Token", "logintoken", Token.Password);
                        Storage.PasswordVault.Add(credentials);
                        App.LogIn();
                        App.SubpageClosed();
                    }
                    else
                    {
                        MessageDialog md = new MessageDialog("Sorry, but that token didn't work. Are you sure it was valid?", "Login failed");
                        await md.ShowAsync();
                    }
                }
            }
            loginButton.IsEnabled   = true;
            ProgressRing.Visibility = Visibility.Collapsed;
            ProgressRing.IsActive   = false;
            LoginText.Visibility    = Visibility.Visible;
        }
Ejemplo n.º 2
0
 private void LoginButton_Click(object sender, RoutedEventArgs e)
 {
     MainContent.Visibility = Visibility.Collapsed;
     CaptchaView.Visibility = Visibility.Visible;
     CaptchaView.Navigate(new Uri("https://discord.com/app"));
 }