Skip to content

Commit 6d59486

Browse files
committed
Added logout functionality
1 parent 6669190 commit 6d59486

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

assign-client/src/main/java/edu/rpi/aris/assign/client/controller/AssignGui.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ public class AssignGui {
2727
@FXML
2828
private Label lblUsername;
2929
@FXML
30+
private Label lblClass;
31+
@FXML
3032
private Button login;
3133
@FXML
34+
private Button refreshButton;
35+
@FXML
3236
private Tab assignmentTab;
3337
@FXML
3438
private Tab studentTab;
3539
@FXML
3640
private Tab problemTab;
41+
@FXML
42+
private MenuItem loginMenu;
3743

3844
private UserInfo userInfo = new UserInfo();
3945
private Stage stage;
@@ -104,9 +110,29 @@ public void initialize() {
104110

105111
login.visibleProperty().bind(userInfo.loginProperty().not());
106112
login.managedProperty().bind(userInfo.loginProperty().not());
113+
login.disableProperty().bind(userInfo.loadingProperty());
114+
115+
classes.visibleProperty().bind(userInfo.loginProperty());
116+
classes.managedProperty().bind(userInfo.loginProperty());
117+
118+
lblClass.visibleProperty().bind(userInfo.loginProperty());
119+
lblClass.managedProperty().bind(userInfo.loginProperty());
120+
121+
refreshButton.visibleProperty().bind(userInfo.loginProperty());
122+
refreshButton.managedProperty().bind(userInfo.loginProperty());
107123

108124
lblUsername.textProperty().bind(Bindings.createStringBinding(() -> userInfo.isLoggedIn() ? Config.USERNAME.getValue() + " (" + userInfo.getUserType().readableName + ")" : "Not Logged In", Config.USERNAME.getProperty(), userInfo.userTypeProperty(), userInfo.loginProperty()));
109125

126+
loginMenu.textProperty().bind(Bindings.createStringBinding(() -> userInfo.loginProperty().get() ? "Logout" : "Login", userInfo.loginProperty()));
127+
loginMenu.disableProperty().bind(userInfo.loadingProperty());
128+
}
129+
130+
@FXML
131+
public void loginOut() {
132+
if (userInfo.loginProperty().get()) {
133+
userInfo.logout();
134+
} else
135+
refresh();
110136
}
111137

112138
@FXML

assign-client/src/main/java/edu/rpi/aris/assign/client/model/UserInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public void getUserInfo(boolean refresh) {
7676
}
7777
}
7878

79+
public void logout() {
80+
loggedIn.set(false);
81+
classes.clear();
82+
classMap.clear();
83+
userType.set(null);
84+
Config.USERNAME.setValue(null);
85+
Config.ACCESS_TOKEN.setValue(null);
86+
}
87+
7988
public void createClass(String name) {
8089
Client.getInstance().processMessage(new ClassCreateMsg(name), createHandler);
8190
}
@@ -97,6 +106,8 @@ public void response(UserGetMsg message) {
97106
});
98107
Collections.sort(classes);
99108
selectedClass.set(classMap.get(Config.SELECTED_COURSE_ID.getValue()));
109+
if (selectedClass.get() == null && classes.size() > 0)
110+
selectedClass.set(classes.get(0));
100111
loggedIn.set(true);
101112
loading.set(false);
102113
});

assign-client/src/main/resources/edu/rpi/aris/assign/client/view/assignment_window.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<menus>
2424
<Menu mnemonicParsing="false" text="User">
2525
<items>
26-
<MenuItem mnemonicParsing="false" text="Login" />
26+
<MenuItem fx:id="loginMenu" mnemonicParsing="false" onAction="#loginOut" text="Login" />
2727
</items>
2828
</Menu>
2929
<Menu mnemonicParsing="false" text="Class">
@@ -64,7 +64,7 @@
6464
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
6565
</HBox.margin>
6666
</Label>
67-
<Button fx:id="login" mnemonicParsing="false" text="Login" />
67+
<Button fx:id="login" mnemonicParsing="false" onAction="#loginOut" text="Login" />
6868
<BorderPane.margin>
6969
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
7070
</BorderPane.margin>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.85
1+
0.0.86
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.85
1+
0.0.86

0 commit comments

Comments
 (0)