private async Task WirelessLogin() { var response = await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); if (response == "Login is successful.") { SetLoginButtonAnimation(); } else if (response == "IP has been online, please logout.") { SetLoginButton(); } else if (response == "E2532: The two authentication interval cannot be less than 3 seconds.") { await Task.Delay(3500); await LoginNetworkIfFavoriteAsync(); } else if (response == "E2553: Password is error.") { CredentialHelper.RemoveAccount(App.Accounts[0].Username); App.Accounts.RemoveAt(0); var localHelper = new LocalObjectStorageHelper(); await localHelper.SaveFileAsync("Accounts", App.Accounts); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); } }
private async Task LoginNetworkIfFavoriteAsync() { var isWired = !NetworkInformation.GetInternetConnectionProfile().IsWlanConnectionProfile&& !NetworkInformation.GetInternetConnectionProfile().IsWwanConnectionProfile; if (isWired) { var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { App.Accounts.Remove(currentAccount); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); return; } await WiredLogin(credential); } else if (!isWired && App.FavoriteNetworks.Where(u => u.Ssid == connectedNetwork.Ssid).Count() != 0) { await WirelessLogin(); var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { App.Accounts.Remove(currentAccount); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); return; } await WiredLogin(credential); } else if (connectedNetwork.Ssid.Contains("Tsinghua")) { await WirelessLogin(); } else { var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); Notification.Show(connectedNetwork.Ssid + ' ' + resourceLoader.GetString("AddFavoritesSuggestion"), 1000 * 10); } }
private async Task WiredLogin(Windows.Security.Credentials.PasswordCredential credential) { var response = await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); if (response == null) { return; } if (response.Contains("login_ok")) { SetLoginButtonAnimation(); await GetConnectionStatusAsync(); var response6 = await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); if (response6 != null && response6.Contains("login_error")) { await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } } else if (response == "ip_already_online_error") { SetLoginButton(); } else if (response == "not_online_error") { await WirelessLogin(); } else if (response.Contains("login_error")) { await Task.Delay(10100); await LoginNetworkIfFavoriteAsync(); } else { CredentialHelper.RemoveAccount(App.Accounts[0].Username); App.Accounts.RemoveAt(0); var localHelper = new LocalObjectStorageHelper(); await localHelper.SaveFileAsync("Accounts", App.Accounts); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); } }
private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { AccountDialog accountDialog = sender as AccountDialog; var username = accountDialog.UsernameTextBox.Text; var originalPassword = accountDialog.PasswordBox.Password; var password = Utility.ComputeMD5(originalPassword); Account newAccount = new Account { Username = username, Password = password }; var duplicatedAccounts = App.Accounts.Where(u => u.Username == newAccount.Username).ToList(); if (duplicatedAccounts.Count > 0) { duplicatedAccounts.Single().Username = newAccount.Username; duplicatedAccounts.Single().Password = newAccount.Password; } else { if (await UseregHelper.LoginAsync(newAccount.Username, newAccount.Password) == "ok") { App.Accounts.Add(newAccount); var localHelper = new LocalObjectStorageHelper(); await localHelper.SaveFileAsync("Accounts", App.Accounts); CredentialHelper.AddAccount(username, originalPassword); } else { var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); ContentDialog contentDialog = new ContentDialog() { Title = resourceLoader.GetString("Error"), Content = resourceLoader.GetString("AccountValidationFail"), PrimaryButtonText = resourceLoader.GetString("Ok") }; await contentDialog.ShowAsync(); } } }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { var isWired = !NetworkInformation.GetInternetConnectionProfile().IsWlanConnectionProfile&& !NetworkInformation.GetInternetConnectionProfile().IsWwanConnectionProfile; if (isOnline == false) { ProgressRing.IsActive = true; await Task.Delay(1000); if (!isWired) { await WirelessLogin(); } else { var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { App.Accounts.Remove(currentAccount); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); return; } await WiredLogin(credential); } await GetConnectionStatusAsync(); await GetUsageChartSourceAsync(); } else { SetLogoutButtonAnimation(); ProgressRing.IsActive = true; await Task.Delay(1500); if (!isWired) { await WirelessLogout(); } else { var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { App.Accounts.Remove(currentAccount); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(WelcomePage)); return; } await WiredLogout(credential); } } }
private async Task Connect() { var localHelper = new LocalObjectStorageHelper(); ObservableCollection <Network> _favoriteNetworks = null; ObservableCollection <Account> _accounts = null; if (await localHelper.FileExistsAsync("Networks")) { _favoriteNetworks = await localHelper.ReadFileAsync <ObservableCollection <Network> >("Networks"); } if (_favoriteNetworks == null) { _favoriteNetworks = new ObservableCollection <Network>(); } if (await localHelper.FileExistsAsync("Accounts")) { _accounts = await localHelper.ReadFileAsync <ObservableCollection <Account> >("Accounts"); } if (_accounts == null) { _accounts = new ObservableCollection <Account>(); } var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (profile != null && _accounts.Count() > 0) { var currentAccount = _accounts.First(); var ssid = profile.ProfileName; var isWired = !profile.IsWlanConnectionProfile && !profile.IsWwanConnectionProfile; if (isWired) { var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } var response = await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); if (response == null) { return; } if (response.Contains("login_ok")) { ShowAutoLoginNotification(ssid); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else if (response == "ip_already_online_error") { ShowAutoLoginNotification(ssid); } else if (response.Contains("login_error")) { await Task.Delay(10100); await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else { ShowWrongPasswordNotification(ssid, currentAccount.Username); } } else if (!isWired && _favoriteNetworks.Where(u => u.Ssid == ssid).Count() != 0) { var response = await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); if (response == "Login is successful.") { ShowAutoLoginNotification(ssid); } else if (response == "E2620: You are already online." || response == "IP has been online, please logout.") { ShowAutoLoginNotification(ssid); } else if (response == "E2532: The two authentication interval cannot be less than 3 seconds.") { await Task.Delay(3500); await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); } else if (response == "E2553: Password is error.") { ShowWrongPasswordNotification(ssid, currentAccount.Username); } var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } response = await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); if (response == null) { return; } if (response.Contains("login_ok")) { ShowAutoLoginNotification(ssid); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else if (response == "ip_already_online_error") { ShowAutoLoginNotification(ssid); } else if (response.Contains("login_error")) { await Task.Delay(10100); await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else { ShowWrongPasswordNotification(ssid, currentAccount.Username); } } else if (ssid.Contains("Tsinghua")) { var response = await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); if (response == "Login is successful.") { ShowAutoLoginNotification(ssid); } else if (response == "E2620: You are already online." || response == "IP has been online, please logout.") { ShowAutoLoginNotification(ssid); } else if (response == "E2532: The two authentication interval cannot be less than 3 seconds.") { await Task.Delay(3500); await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); } else if (response == "E2553: Password is error.") { ShowWrongPasswordNotification(ssid, currentAccount.Username); } var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } } } else { ToastNotificationManager.History.Clear(); } }