Exemplo n.º 1
0
 private void butLoginM_Click(object sender, RoutedEventArgs e)
 {
     auth = new Launch.Login.YggdrasilLoginAuth(txtBoxUNE.Text, pwbox.Password);
     if (requiredPreLogin)
     {
         info = auth.Login();
         auth = !string.IsNullOrWhiteSpace(info.ErrorMsg) ? null : new Launch.Login.YggdrasilRefreshAuth(info.Session);
     }
     if ((bool)butRM2.IsChecked)
     {
         MeCore.Config.username = txtBoxUNE.Text;
         MeCore.Config.Save(null);
     }
     else
     {
         MeCore.Config.QuickChange("username", "");
     }
     if ((bool)butRPW.IsChecked)
     {
         MeCore.Config.ScoreStringToOver50(pwbox.Password);
         MeCore.Config.Save(null);
     }
     else
     {
         MeCore.Config.QuickChange("password", "");
     }
     DialogResult = true;
     Close();
 }
Exemplo n.º 2
0
 public AuthInfo Login()
 {
     AuthInfo AI = new AuthInfo();
     try
     {
         HttpWebRequest auth = (HttpWebRequest)WebRequest.Create(helper.Validate);
         auth.Method = "POST";
         auth.ContentType = "application/json";
         RefreshRequest ag = new RefreshRequest(AccessToken);
         string logindata = JsonConvert.SerializeObject(ag, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
         byte[] postdata = Encoding.UTF8.GetBytes(logindata);
         auth.ContentLength = postdata.LongLength;
         Stream poststream = auth.GetRequestStream();
         poststream.Write(postdata, 0, postdata.Length);
         poststream.Close();
         HttpWebResponse authans = (HttpWebResponse)auth.GetResponse();
         if(authans.StatusCode == HttpStatusCode.NoContent)
         {
             AI.Pass = true;
             return AI;
         }
         AI.Pass = false;
         return AI;
     }
     catch (WebException ex)
     {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message + new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
         return AI;
     }
     catch (Exception ex)
     {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message;
         return AI;
     }
 }
Exemplo n.º 3
0
 public AuthInfo Login()
 {
     AuthInfo AI = new AuthInfo();
     try
     {
         HttpWebRequest auth = (HttpWebRequest)WebRequest.Create(helper.Refresh);
         auth.Method = "POST";
         auth.ContentType = "application/json";
         RefreshRequest ag = new RefreshRequest(AccessToken);
         string logindata = JsonConvert.SerializeObject(ag, Formatting.None, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
         byte[] postdata = Encoding.UTF8.GetBytes(logindata);
         auth.ContentLength = postdata.LongLength;
         Stream poststream = auth.GetRequestStream();
         poststream.Write(postdata, 0, postdata.Length);
         poststream.Close();
         HttpWebResponse authans = (HttpWebResponse)auth.GetResponse();
         StreamReader ResponseStream = new StreamReader(authans.GetResponseStream());
         Response response = JsonConvert.DeserializeObject<Response>(ResponseStream.ReadToEnd());
         if (response.clientToken != MeCore.Config.GUID)
         {
             AI.ErrorMsg += "Client Token unmatched.";
         }
         if (response.selectedProfile != null) {
             AI.DisplayName = response.selectedProfile.name;
             AI.UUID = response.selectedProfile.id;
         }
         AI.Pass = true;
         AI.Session = response.accessToken;
         if (response.user != null)
         {
             AI.UserType = response.user.legacy ? "Legacy" : "Mojang";
             AI.Prop = response.user.properties != null ? JsonConvert.SerializeObject(response.user.properties, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) : "{}";
         }
         else
         {
             AI.UserType = "Mojang"; AI.Prop = "{}";
         }
         return AI;
     }
     catch (WebException ex) {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message + new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
         return AI;
     }
     catch (Exception ex) {
         AI.Pass = false;
         AI.ErrorMsg = ex.Message;
         return AI;
     }
 }
Exemplo n.º 4
0
 private void butLoginOff_Click(object sender, RoutedEventArgs e)
 {
     auth = new Launch.Login.OfflineAuth(txtBoxUN.Text);
     if (requiredPreLogin)
     {
         info = auth.Login();
         auth = !string.IsNullOrWhiteSpace(info.ErrorMsg) ? null : new Launch.Login.AuthWarpper(info);
     }
     if ((bool)butRM1.IsChecked)
     {
         MeCore.Config.username = txtBoxUN.Text;
         MeCore.Config.Save(null);
     }
     DialogResult = true;
     Close();
 }
Exemplo n.º 5
0
 private void CreateCustomAuth()
 {
     if (MeCore.Config.Server.Auths.Count != 0)
     {
         short i = 0;
         foreach (var item in MeCore.Config.Server.Auths)
         {
             ++i;
             Grid gridCustomAuth = new Grid();
             gridCustomAuth.Visibility = Visibility.Collapsed;
             Label lbltitie = new Label();
             lbltitie.SetLocalizedContent("Login");
             lbltitie.FontSize = 21.333;
             lbltitie.Margin = new Thickness(10, 10, 0, 0);
             lbltitie.HorizontalAlignment = HorizontalAlignment.Left;
             lbltitie.VerticalAlignment = VerticalAlignment.Top;
             gridCustomAuth.Children.Add(lbltitie);
             Label lblune = new Label();
             lblune.SetLocalizedContent("UNEM");
             lblune.FontSize = 16;
             lblune.Margin = new Thickness(10, 45, 0, 0);
             lblune.HorizontalAlignment = HorizontalAlignment.Left;
             lblune.VerticalAlignment = VerticalAlignment.Top;
             gridCustomAuth.Children.Add(lblune);
             TextBox txtboxune = new TextBox();
             txtboxune.Text = "";
             txtboxune.FontSize = 18.667;
             txtboxune.Margin = new Thickness(10, 75, 10, 0);
             txtboxune.Height = 30;
             txtboxune.HorizontalAlignment = HorizontalAlignment.Stretch;
             txtboxune.VerticalAlignment = VerticalAlignment.Top;
             txtboxune.TextWrapping = TextWrapping.Wrap;
             gridCustomAuth.Children.Add(txtboxune);
             Label lblpw = new Label();
             lblpw.SetLocalizedContent("PW");
             lblpw.FontSize = 16;
             lblpw.Margin = new Thickness(10, 105, 0, 0);
             lblpw.HorizontalAlignment = HorizontalAlignment.Left;
             lblpw.VerticalAlignment = VerticalAlignment.Top;
             gridCustomAuth.Children.Add(lblpw);
             PasswordBox pwbox = new PasswordBox();
             pwbox.Password = "";
             pwbox.FontSize = 18.667;
             pwbox.Margin = new Thickness(10, 135, 10, 0);
             pwbox.Height = 30;
             pwbox.HorizontalAlignment = HorizontalAlignment.Stretch;
             pwbox.VerticalAlignment = VerticalAlignment.Top;
             gridCustomAuth.Children.Add(pwbox);
             Button butback = new Button();
             butback.SetLocalizedContent("Back");
             butback.FontSize = 16;
             butback.Margin = new Thickness(0, 0, 10, 10);
             butback.Width = 202; butback.Height = 32;
             butback.HorizontalAlignment = HorizontalAlignment.Right;
             butback.VerticalAlignment = VerticalAlignment.Bottom;
             butback.BorderThickness = new Thickness(2);
             butback.Style = (Style)Resources["NormalButton"];
             butback.Click += delegate (object sender, RoutedEventArgs e) {
                 gridCustomAuth.Visibility = Visibility.Collapsed;
                 gridMenu.Visibility = Visibility.Visible;
             };
             gridCustomAuth.Children.Add(butback);
             Button butlogin = new Button();
             butlogin.SetLocalizedContent("Login");
             butlogin.FontSize = 16;
             butlogin.Margin = new Thickness(0, 0, 217, 10);
             butlogin.Width = 202; butlogin.Height = 32;
             butlogin.HorizontalAlignment = HorizontalAlignment.Right;
             butlogin.VerticalAlignment = VerticalAlignment.Bottom;
             butlogin.BorderThickness = new Thickness(2);
             butlogin.Style = (Style)Resources["NormalButton"];
             butlogin.Click += delegate (object sender, RoutedEventArgs e) {
                 auth = new Launch.Login.YggdrasilLoginAuth(txtboxune.Text, pwbox.Password,new Launch.Login.YggdrasilHelper(item.Url));
                 if (requiredPreLogin)
                 {
                     info = auth.Login();
                     auth = !string.IsNullOrWhiteSpace(info.ErrorMsg) ? null : new Launch.Login.YggdrasilRefreshAuth(info.Session, new Launch.Login.YggdrasilHelper(item.Url));
                 }
                 Close();
             };
             gridCustomAuth.Children.Add(butlogin);
             gridMain.Children.Add(gridCustomAuth);
             ButtonMenu butcustomauth = new ButtonMenu();
             butcustomauth.Content = string.Format(Lang.LangManager.GetLangFromResource("Online"), item.Name);
             butcustomauth.MenuImage = new BitmapImage(new Uri("pack://application:,,,/Resources/others.png"));
             butcustomauth.FontSize = 16;
             butcustomauth.Margin = new Thickness(0, 60 * (i + 1), -17, 0);
             butcustomauth.Height = 60;
             butcustomauth.Background = new SolidColorBrush(Colors.White);
             butcustomauth.VerticalAlignment = VerticalAlignment.Top;
             butcustomauth.Style = (Style)Resources["ButtonMeListSolid"];
             butcustomauth.ListType = true;
             butcustomauth.Click += delegate (object sender, RoutedEventArgs e) {
                 gridMenu.Visibility = Visibility.Collapsed;
                 gridCustomAuth.Visibility = Visibility.Visible;
             };
             gridscrolllist.Children.Add(butcustomauth);
         }
     }
 }
Exemplo n.º 6
0
 public AuthWarpper(AuthInfo info)
 {
     this.info = info;
 }