Skip to content

Commit

Permalink
添加更多登录方式
Browse files Browse the repository at this point in the history
  • Loading branch information
RedDragon0293 committed Apr 7, 2024
1 parent ad7cda6 commit 0502fa3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: EPortal-${{ github.event.head_commit.id }}
name: EPortal
path: build/libs/shadow

# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
Expand Down
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/main/java/cn/reddragon/eportal/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,26 @@ private static String updateSessionInternal() {
//System.out.println(resultJson.toString());
String r = resultJson.get("result").getAsString();
if (Objects.equals(r, "success")) {
//更新userIndex
Authenticator.userIndex = resultJson.get("userIndex").getAsString();
// 获取当前用户
Platform.runLater(() -> HelloApplication.controller.user.setText("User: " + resultJson.get("userName").getAsString() + " (" + resultJson.get("userId").getAsString() + ")"));
// 获取运营商、剩余时间
JsonArray ballArray = JsonParser.parseString(resultJson.get("ballInfo").getAsString()).getAsJsonArray();
if (ballArray.get(1).getAsJsonObject().get("value").getAsString().equals("中国移动")) {
Authenticator.type = LoginType.CHINAMOBILE;
if (ballArray.get(1).getAsJsonObject().get("displayName").getAsString().equals("我的运营商")) {
for (LoginType it : LoginType.values()) {
if (it.authName.contains(ballArray.get(1).getAsJsonObject().get("value").getAsString())) {
Authenticator.type = it;
}
}
Platform.runLater(() -> HelloApplication.controller.remainLabel.setText("Time remaining: ∞"));
return r;
}
Authenticator.type = LoginType.WAN;
int duration = ballArray.get(1).getAsJsonObject().get("value").getAsInt();
StringBuilder sb = new StringBuilder();
sb.append("Time remaining: ");
//计算剩余时间
int h = duration / 3600;
int m = (duration % 3600) / 60;
int s = (duration % 3600) % 60;
Expand All @@ -201,7 +208,7 @@ private static String updateSessionInternal() {
}
Platform.runLater(() -> HelloApplication.controller.remainLabel.setText(sb.toString()));
} else if (!Objects.equals(r, "wait")) {
Authenticator.type = LoginType.OFFLINE;
//Authenticator.type = LoginType.OFFLINE;
Platform.runLater(() -> HelloApplication.controller.resultText.setText(resultJson.get("message").getAsString()));
}
return r;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/cn/reddragon/eportal/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Objects;

public class HelloApplication extends Application {
public static HelloController controller;
Expand Down Expand Up @@ -54,8 +55,13 @@ public void start(Stage stage) throws IOException {
Parent root = fxmlLoader.load();
controller = fxmlLoader.getController();
Scene scene = new Scene(root);
ChoiceBox box = (ChoiceBox) root.lookup("#selector");
box.getItems().addAll("LAN", "WAN", "ChinaMobile");
ChoiceBox<String> box = (ChoiceBox<String>) root.lookup("#selector");
//box.getItems().addAll("LAN", "WAN", "ChinaMobile");
for (LoginType it : LoginType.values()) {
if (!Objects.equals(it.displayName, "")) {
box.getItems().add(it.displayName);
}
}
stage.setTitle("EPortal");
stage.setScene(scene);
stage.setMinWidth(root.prefWidth(-1));
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/cn/reddragon/eportal/HelloController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Objects;

public class HelloController {
@FXML
Expand All @@ -41,10 +42,19 @@ public void updateUI() {
if (Authenticator.getOnline()) {
button.setText("Logout");
sb.append("Online ");
for (LoginType it : LoginType.values()) {
if (Objects.equals(it, Authenticator.type)) {
sb.append('(');
sb.append(it.displayName);
sb.append(')');
}
}
/*
if (Authenticator.type == LoginType.CHINAMOBILE)
sb.append("(ChinaMobile)");
else
sb.append("(WAN)");
*/
} else {
button.setText("Login");
sb.append("Offline");
Expand Down Expand Up @@ -92,6 +102,7 @@ protected void onLoginButtonClick() {
String pw = URIEncoder.encodeURI(URIEncoder.encodeURI(password));
String mode = (String) selector.getValue();
String serviceString = "";
/*
if (mode.equals("LAN")) {
serviceString = URIEncoder.encodeURI(URIEncoder.encodeURI("校园内网服务(in-campus NET)"));
} else if (mode.equals("WAN")) {
Expand All @@ -100,6 +111,13 @@ protected void onLoginButtonClick() {
} else if (mode.equals("ChinaMobile")) {
serviceString = URIEncoder.encodeURI(URIEncoder.encodeURI("中国移动(CMCC NET)"));
}
*/
for (LoginType it : LoginType.values()) {
if (Objects.equals(it.displayName, mode)) {
serviceString = URIEncoder.encodeURI(URIEncoder.encodeURI(it.authName));
break;
}
}
try {
//获取queryString
HttpURLConnection connection = HttpUtils.make("http://123.123.123.123", "GET");
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/cn/reddragon/eportal/LoginType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package cn.reddragon.eportal;

public enum LoginType {
CHINAMOBILE, WAN, OFFLINE
WAN("校园外网服务(out-campus NET)", "CampusNet"),
CHINAMOBILE("中国移动(CMCC NET)", "ChinaMobile"),
CHINATELECOM("中国电信(常州)", "ChinaTelecom"),
CHINAUNICOM("中国联通(常州)", "ChinaUnicom");
public final String authName, displayName;

LoginType(String authName, String displayName) {
this.authName = authName;
this.displayName = displayName;
}
}

0 comments on commit 0502fa3

Please sign in to comment.