|
15 | 15 | import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
|
16 | 16 | import fi.helsinki.cs.tmc.events.LoginStateChangedEvent;
|
17 | 17 | import fi.helsinki.cs.tmc.model.CourseDb;
|
| 18 | +import fi.helsinki.cs.tmc.tailoring.SelectedTailoring; |
18 | 19 | import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
|
19 | 20 | import fi.helsinki.cs.tmc.ui.CourseListWindow;
|
20 | 21 | import fi.helsinki.cs.tmc.ui.LoginDialog;
|
21 | 22 | import fi.helsinki.cs.tmc.ui.OrganizationListWindow;
|
22 | 23 |
|
23 |
| -import java.awt.event.ActionEvent; |
24 |
| -import java.awt.event.ActionListener; |
25 | 24 | import java.io.FileNotFoundException;
|
26 | 25 | import java.io.IOException;
|
| 26 | +import java.net.MalformedURLException; |
27 | 27 | import java.net.UnknownHostException;
|
28 | 28 | import java.util.logging.Level;
|
29 | 29 | import java.util.logging.Logger;
|
@@ -69,26 +69,40 @@ public void run() {
|
69 | 69 | normalizer.selectOrganizationAndCourse();
|
70 | 70 | } catch (Exception ex) {
|
71 | 71 | log.log(Level.WARNING, "Error while logging in! " + ex.toString());
|
| 72 | + final ConvenientDialogDisplayer displayer = ConvenientDialogDisplayer.getDefault(); |
| 73 | + final TmcSettings settings = TmcSettingsHolder.get(); |
| 74 | + final String serverAddress = settings.getServerAddress(); |
72 | 75 | if (ex instanceof IOException) {
|
73 | 76 | connectionException = (IOException) ex;
|
74 | 77 | if (ex instanceof UnknownHostException) {
|
75 |
| - ConvenientDialogDisplayer.getDefault().displayError("Couldn't connect to the server. Please check your internet connection."); |
| 78 | + displayer.displayError("Couldn't connect to the server. Please check your internet connection."); |
76 | 79 | } else if (ex instanceof FileNotFoundException) {
|
77 |
| - if (TmcSettingsHolder.get().getServerAddress().contains("tmc.mooc.fi/mooc")) { |
78 |
| - ConvenientDialogDisplayer.getDefault().displayError("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" + |
| 80 | + if (serverAddress.contains("tmc.mooc.fi/mooc")) { |
| 81 | + displayer.displayError("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" + |
79 | 82 | "All the courses have been migrated to our main server https://tmc.mooc.fi.\n" +
|
80 | 83 | "If you'd like to do the migrated courses, you'll need to update your server address to\n" +
|
81 |
| - "https://tmc.mooc.fi/org/mooc and create a new account there.\n\n" + |
| 84 | + "https://tmc.mooc.fi and create a new account there.\n" + |
| 85 | + "After that, choose the MOOC organization after logging in.\n\n" + |
82 | 86 | "For more information, check the course materials on mooc.fi.");
|
83 | 87 | } else {
|
84 |
| - ConvenientDialogDisplayer.getDefault().displayError("Server address is incorrect or the server is not supported."); |
| 88 | + displayer.displayError("Server address is incorrect or the server is not supported."); |
85 | 89 | }
|
| 90 | + } else if (ex instanceof MalformedURLException) { |
| 91 | + displayer.displayError("Malformed server address! Resetting to default."); |
| 92 | + final String defaultServerUrl = SelectedTailoring.get().getDefaultServerUrl(); |
| 93 | + settings.setServerAddress(defaultServerUrl); |
86 | 94 | }
|
87 | 95 | } else if (ex instanceof AuthenticationFailedException) {
|
88 | 96 | authenticationException = (AuthenticationFailedException) ex;
|
89 |
| - ConvenientDialogDisplayer.getDefault().displayError("Username or password is incorrect.", ex); |
| 97 | + displayer.displayError("Username or password is incorrect.", ex); |
90 | 98 | } else {
|
91 |
| - ConvenientDialogDisplayer.getDefault().displayError("Logging in failed! Try again."); |
| 99 | + if (serverAddress.contains("tmc.mooc.fi") && !serverAddress.contains("https://")) { |
| 100 | + displayer.displayError("Malformed server address! Resetting to default."); |
| 101 | + final String defaultServerUrl = SelectedTailoring.get().getDefaultServerUrl(); |
| 102 | + settings.setServerAddress(defaultServerUrl); |
| 103 | + } else { |
| 104 | + displayer.displayError("Logging in failed! Try again."); |
| 105 | + } |
92 | 106 | }
|
93 | 107 | }
|
94 | 108 | setReady(true);
|
|
0 commit comments