Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 07e4bcf

Browse files
author
Irene
committed
Fix logging in on changing server address
Logging in now loops until login is successful. Also made the login messages more clear, and validated login first in the command paste Also fix not filling out username if login failed
1 parent 4792045 commit 07e4bcf

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/main/java/fi/helsinki/cs/tmc/cli/command/ConfigCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ public void setter(String value) throws BadValueTypeException {
8585
context.getSettings().setServerAddress(addr);
8686
normalizeServerAddress();
8787
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
88-
io.println("Please login again to use the new server.");
8988
SettingsIo.delete();
89+
io.println("You have been logged out.");
90+
io.println("Please login again to use the new server.");
9091
LoginCommand loginCommand = new LoginCommand();
91-
loginCommand.login(context, null, Optional.of(value));
92+
while (!loginCommand.login(context, null, Optional.of(value))) {
93+
io.println("Please login again.");
94+
}
9295
}
9396
});
9497
ALLOWED_KEYS.put(testResultRightKey, new PropertyFunctions() {
@@ -291,7 +294,7 @@ private void setProperties(String[] arguments) {
291294
String oldValue = properties.get(parts[0]);
292295
if (parts[0].equals(serverAddressKey)) {
293296
io.println("All courses are now hosted at https://tmc.mooc.fi. We do not advise changing the server address.");
294-
if (parts[0].contains("tmc.mooc.fi/mooc")) {
297+
if (parts[1].contains("tmc.mooc.fi/mooc")) {
295298
io.println("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" +
296299
"If you'd like to do the migrated courses, you'll have to create an account on the new server.\n" +
297300
"Choose the MOOC organization when logging in.\n\n" +

src/main/java/fi/helsinki/cs/tmc/cli/command/LoginCommand.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public void run(CliContext context, CommandLine args) {
5656
(organization.isPresent() ?
5757
" and your current organization is " + organization.get().getName() :
5858
"."));
59-
io.println("Change your organization with the command organization.");
60-
io.println("Inspect and change your current settings with the command config.");
59+
io.println("You can change your organization with the command organization.");
60+
io.println("You can change your current settings with the command config.");
6161
return;
6262
}
6363

@@ -75,7 +75,7 @@ public void run(CliContext context, CommandLine args) {
7575
login(this.ctx, args, Optional.absent());
7676
}
7777

78-
public void login(CliContext ctx, CommandLine args, Optional<String> serverAddress) {
78+
public boolean login(CliContext ctx, CommandLine args, Optional<String> serverAddress) {
7979
Io io = ctx.getIo();
8080
username = getLoginInfo(args, username, "u", "username: ", io);
8181
password = getLoginInfo(args, null, "p", "password: ", io);
@@ -89,21 +89,22 @@ public void login(CliContext ctx, CommandLine args, Optional<String> serverAddre
8989

9090
if (!TmcUtil.tryToLogin(ctx, account, password)) {
9191
ctx.getSettings().setAccount(ctx, new Account());
92-
return;
92+
username = null;
93+
return false;
9394
}
9495

9596
OrganizationCommand organizationCommand = new OrganizationCommand();
96-
Optional<Organization> organization = organizationCommand.chooseOrganization(ctx, Optional.of(args));
97+
Optional<Organization> organization = organizationCommand.chooseOrganization(ctx, Optional.fromNullable(args));
9798
if (!organization.isPresent()) {
98-
return;
99+
return false;
99100
}
100101
account.setOrganization(organization);
101102

102-
boolean sendDiagnostics = getBooleanAnswerFromUser(Optional.of(username),
103+
boolean sendDiagnostics = getBooleanAnswerFromUser(Optional.fromNullable(username),
103104
"Do you want to send crash reports for client development?",
104105
ctx.getSettings().getSendDiagnostics(), io);
105106
account.setSendDiagnostics(sendDiagnostics);
106-
boolean sendAnalytics = getBooleanAnswerFromUser(Optional.of(username),
107+
boolean sendAnalytics = getBooleanAnswerFromUser(Optional.fromNullable(username),
107108
"Do you want to send analytics data for research?",
108109
ctx.getSettings().isSpywareEnabled(), io);
109110
account.setSendAnalytics(sendAnalytics);
@@ -112,14 +113,15 @@ public void login(CliContext ctx, CommandLine args, Optional<String> serverAddre
112113
list.addAccount(account);
113114
if (!SettingsIo.saveAccountList(list)) {
114115
io.errorln("Failed to write the accounts file.");
115-
return;
116+
return false;
116117
}
117118

118119
ctx.getAnalyticsFacade().saveAnalytics("login");
119120

120121
io.println("Login successful.");
121122
io.println("You can change your organization with the command organization, " +
122-
"and inspect and change other settings with the command config.");
123+
"and change other settings with the command config.");
124+
return true;
123125
}
124126

125127
private String getLoginInfo(CommandLine line, String oldValue, String option, String prompt, Io io) {

src/main/java/fi/helsinki/cs/tmc/cli/command/PasteCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public void run(CliContext context, CommandLine args) {
4848
this.io = context.getIo();
4949
WorkDir workdir = ctx.getWorkDir();
5050

51-
if (!parseArgs(args)) {
51+
if (!ctx.checkIsLoggedIn(false, true)) {
5252
return;
5353
}
5454

55-
if (!ctx.checkIsLoggedIn(false, true)) {
55+
if (!parseArgs(args)) {
5656
return;
5757
}
5858

0 commit comments

Comments
 (0)