async Task CallLogin(bool createAccount) { _sendingLogin = true; CommandManager.InvalidateRequerySuggested(); var result = await ParentViewModel.Game.Client.Login(LoginName, LoginPassword.ConvertToUnsecureString(), createAccount); _sendingLogin = false; if (result == LoginCheckResult.LoginOK) { IsLoggingIn = false; _gameListUpdateTimer.Change(0, System.Threading.Timeout.Infinite); } else if (result == LoginCheckResult.AccountDisabled) { if (createAccount) { MessageBox.Show("Account was requested.\r\nPlease wait until the administrator unlocks the account."); } else { MessageBox.Show("Account is disabled.\r\nPlease wait until the administrator unlocks the account."); } } else if (result == LoginCheckResult.CreateAccountDenied) { MessageBox.Show("Create account denied!"); _canCreateAccount = false; } CommandManager.InvalidateRequerySuggested(); // TODO: We must check if the server is still connected. There is currently no feedback. This must be done directly on the socket. }
void Validate([CallerMemberName] string propertyName = null) { List <string> errors; if (!_errors.TryGetValue(propertyName, out errors)) { errors = new List <string>(); _errors[propertyName] = errors; } StringBuilder builder; switch (propertyName) { case nameof(LoginName): errors.Clear(); if (LoginName?.Length > 0 && !Regex.IsMatch(LoginName, @"^[\x21-\x7E]+$")) { errors.Add("Invalid symbols (space is not allowed)"); } if (LoginName?.Length > 32) { errors.Add("Max length is 32"); } ErrorText = ""; builder = new StringBuilder(); builder.Append(ErrorText); foreach (var str in errors) { builder.Append(str + "\r\n"); } ErrorText = builder.ToString().TrimEnd(new[] { '\r', '\n' }); break; case nameof(LoginPassword): errors.Clear(); if (LoginPassword?.ConvertToUnsecureString()?.Length > 0 && !Regex.IsMatch(LoginPassword?.ConvertToUnsecureString() ?? "", @"^[\x20-\x7E]+$")) { errors.Add("Invalid symbols"); } if (LoginPassword?.ConvertToUnsecureString()?.Length > 32) { errors.Add("Max length is 32"); } ErrorText = ""; builder = new StringBuilder(); builder.Append(ErrorText); foreach (var str in errors) { builder.Append(str + "\r\n"); } ErrorText = builder.ToString().TrimEnd(new[] { '\r', '\n' }); break; case nameof(NewGameText): errors.Clear(); builder = new StringBuilder(); if (NewGameText?.Length > 0 && !Regex.IsMatch(NewGameText, @"^[\x20-\x7E]+$")) { errors.Add("Invalid symbols"); } if (NewGameText?.Length > 32) { errors.Add("Max length is 32"); } builder = new StringBuilder(); GameTextErrorText = ""; builder.Append(ErrorText); foreach (var str in errors) { builder.Append(str + "\r\n"); } GameTextErrorText = builder.ToString().TrimEnd(new[] { '\r', '\n' }); break; } HasErrors = _errors.Any(o => o.Value?.Count > 0); ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName)); }