/// <summary> /// Handle login button event. Send information to server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, RoutedEventArgs e) { logger.Info("loginButton_Click"); if (!Regex.IsMatch(emailAddrTextBox.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { errorMessage.Content = "Enter a valid email."; emailAddrTextBox.Select(0, emailAddrTextBox.Text.Length); emailAddrTextBox.Focus(); } else if (PassTextBox.Password.Length == 0) { errorMessage.Content = "Enter password."; PassTextBox.Focus(); } else { using (new CursorWait()) { LoginData loginData = new LoginData(); loginData.EmailAddress = emailAddrTextBox.Text; loginData.Password = PassTextBox.Password; LoginResult result = service.UserLogin(loginData); switch (result.Status) { case OperationStatus.Success: { Properties.Settings.Default.email = emailAddrTextBox.Text; Properties.Settings.Default.password = PassTextBox.Password; Properties.Settings.Default.Save(); WelcomePage welcome = new WelcomePage(service, result.NickName, emailAddrTextBox.Text); NavigationService.Navigate(welcome); } break; case OperationStatus.Failure: errorMessage.Content = "Internal server error"; break; case OperationStatus.InvalidEmail: errorMessage.Content = "Email address doesn't exist"; break; case OperationStatus.InvalidPassword: errorMessage.Content = "The password is incorrect"; break; } } } }
public MainWindow() { InitializeComponent(); bool showWelcome = false; try { //Open connection to the server service.Open(); ((ICommunicationObject)service).Faulted += new EventHandler(delegate { MessageBox.Show("Service faulted!"); }); showWelcome = true; } catch (Exception e) { logger.ErrorFormat("Main Window - Exception: {0}", e.Message); showWelcome = false; } if (showWelcome) { string email = Properties.Settings.Default.email; string pass = Properties.Settings.Default.password; WelcomePage welcome; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(pass)) { welcome = new WelcomePage(service); } else { LoginData loginData = new LoginData(); loginData.EmailAddress = email; loginData.Password = pass; LoginResult result = service.UserLogin(loginData); if (result.Status == OperationStatus.Success) { welcome = new WelcomePage(service, result.NickName, email); } else { welcome = new WelcomePage(service); } } mainFrame.NavigationService.Navigate(welcome); } else { string message = "Failed to connect to server!" + Environment.NewLine + "Try to connect later."; ErrorPage errorPage = new ErrorPage(message); mainFrame.NavigationService.Navigate(errorPage); } }