private void openLogin() { if (!loggedin) { Login lw = new Login(); bool loginAuthorized = false; bLogInOut.IsEnabled = false; lw.Username = connectionSettings.readSetting("account", "username"); lw.Password = connectionSettings.readSetting("account", "password"); while (!loginAuthorized) { lw.showLogin(); try { switch (lw.waitResponse()) { case Login.LoginResponse.CANCEL: lw.Close(); bLogInOut.IsEnabled = true; return; case Login.LoginResponse.LOGIN: Command loginComm = new ComandoLogin(lw.Username, lw.Password); loginAuthorized = loginComm.esegui(); if (!loginAuthorized) { lw.ErrorMessage = "Login failed"; } break; case Login.LoginResponse.REGISTER: Command regComm = new ComandoRegistra(lw.Username, lw.Password); loginAuthorized = regComm.esegui(); if (!loginAuthorized) { lw.ErrorMessage = "Registration failed"; } break; default: throw new Exception("Not implemented"); } if (loginAuthorized) { lUsername.Content = lw.Username; bLogInOut.Content = "Logout"; lw.Close(); connectionSettings.writeSetting("account", "username", lw.Username); connectionSettings.writeSetting("account", "password", lw.Password); bStart.IsEnabled = true; loggedin = true; updateStatus("Logged in"); } } catch (Exception ex) when (ex is ServerException || ex is ClientException) { lw.ErrorMessage = ex.Message; loginAuthorized = false; } } bLogInOut.IsEnabled = true; } }
private void openLogin() { if (!loggedin) { Login lw = new Login(); bool loginAuthorized = false; bLogInOut.IsEnabled = false; lw.Username = connectionSettings.readSetting("account", "username"); lw.Password = connectionSettings.readSetting("account", "password"); while (!loginAuthorized) { lw.showLogin(); try { switch (lw.waitResponse()) { case Login.LoginResponse.CANCEL: lw.Close(); bLogInOut.IsEnabled = true; return; case Login.LoginResponse.LOGIN: Command loginComm = new ComandoLogin(lw.Username, lw.Password); loginAuthorized = loginComm.esegui(); if (!loginAuthorized) { lw.ErrorMessage = "Login failed"; } break; case Login.LoginResponse.REGISTER: Command regComm = new ComandoRegistra(lw.Username, lw.Password); loginAuthorized = regComm.esegui(); if (!loginAuthorized) { lw.ErrorMessage = "Registration failed"; } break; default: throw new Exception("Not implemented"); } if (loginAuthorized) { lUsername.Content = lw.Username; bLogInOut.Content = "Logout"; lw.Close(); connectionSettings.writeSetting("account", "username", lw.Username); connectionSettings.writeSetting("account", "password", lw.Password); bStart.IsEnabled = true; loggedin = true; updateStatus("Logged in"); } } catch (Exception ex) when(ex is ServerException || ex is ClientException) { lw.ErrorMessage = ex.Message; loginAuthorized = false; } } bLogInOut.IsEnabled = true; } }