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 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(); } }