private async Task <int> CheckLogin(int owner) { if (App.Token == default) { if (string.IsNullOrWhiteSpace(Settings.Default.Username) || string.IsNullOrWhiteSpace(Settings.Default.Password)) { MainWindow.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(this, ApiUrl, owner); }); return(-1); } string login = Settings.Default.Username; string passwd = Utils.PasswordEncryptor.Decrypt(Settings.Default.Password, login.Trim()); ObjectResult <LoginContent> result = await WebWrapper.Login(login, passwd, ApiUrl); if (result == null || result.code != 1 || result.content == null || result.content.privileges < 0) { MainWindow.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(this, ApiUrl, owner); }); return(-1); } LoginContent loginContent = result.content; App.Token = loginContent.token; } return(1); }
public static async Task <bool> CheckLogin(Action callback, MainWindow mw, Uri ApiUrl) { if (App.Token == default) { if (string.IsNullOrWhiteSpace(Settings.Default.Username) || string.IsNullOrWhiteSpace(Settings.Default.Password)) { mw.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(ApiUrl, callback); }); return(false); } string login = Settings.Default.Username; string passwd = PasswordEncryptor.Decrypt(Settings.Default.Password, login.Trim()); ObjectResult <LoginContent> result = await WebWrapper.Login(login, passwd, ApiUrl); if (result == null || !IsSuccessStatusCode(result.code) || result.content == null || result.content.privileges < 0) { mw.Dispatcher.Invoke(() => { LoginDialog ld = new LoginDialog(ApiUrl, callback); }); return(false); } LoginContent loginContent = result.content; App.Token = loginContent.token; } if (!mw.ReportedDLC) { mw.ReportDLC(); } return(true); }
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { string login = Username.Text; string pass = Password.Password; if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(pass)) { args.Cancel = true; ErrorLabel.Content = "You haven't filled all required fields."; ErrorLabel.Visibility = Visibility.Visible; } else { Task.Run(async() => { ObjectResult <LoginContent> result = await WebWrapper.Login(login.Trim(), pass, ApiUrl); if (result != null && result.code == 1 && result.content?.privileges >= 0) { Settings.Default.Username = login.Trim(); Settings.Default.Password = Utils.PasswordEncryptor.Encrypt(pass, login.Trim()); Settings.Default.Save(); App.Token = result.content.token; switch (Invoker) { case 0: PM.DownloadDependencies(); break; case 1: PM.CheckUpdates(); break; } } else { args.Cancel = true; new Task(() => { Dispatcher.Invoke(() => { ErrorLabel.Content = result.message; ErrorLabel.Visibility = Visibility.Visible; }); }).Start(); } }).Wait(); } }
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { string login = Username.Text; string pass = Password.Password; if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(pass)) { args.Cancel = true; ErrorLabel.Content = Localization.Strings.LoginMissingField; ErrorLabel.Visibility = Visibility.Visible; } else { Task.Run(async() => { ObjectResult <LoginContent> result = await WebWrapper.Login(login.Trim(), pass, ApiUrl); if (result != null && Utils.IsSuccessStatusCode(result.code) && result.content?.privileges >= 0) { Settings.Default.Username = login.Trim(); Settings.Default.Password = Utils.PasswordEncryptor.Encrypt(pass, login.Trim()); Settings.Default.Save(); App.Token = result.content.token; CallBack(); } else { args.Cancel = true; new Task(() => { Dispatcher.Invoke(() => { if (result != null) { ErrorLabel.Content = result.message; } else { ErrorLabel.Content = Localization.Strings.UnknownError; } ErrorLabel.Visibility = Visibility.Visible; }); }).Start(); } }).Wait(); } }