From cc868656a8f4adb5ec61670bd8ed2fa1c611f5e9 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 28 Aug 2021 16:27:27 +0800 Subject: [PATCH] fix: mess code in Microsoft login page. Closes #981. --- .../hmcl/game/MicrosoftAuthenticationServer.java | 7 +++++-- HMCL/src/main/resources/assets/lang/I18N.properties | 4 ++++ .../main/resources/assets/lang/I18N_zh_CN.properties | 4 ++++ HMCL/src/main/resources/assets/microsoft_auth.html | 11 +++-------- .../java/org/jackhuang/hmcl/util/io/HttpRequest.java | 9 +++++---- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java index a91719526..a0ef169c5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/MicrosoftAuthenticationServer.java @@ -27,6 +27,7 @@ import org.jackhuang.hmcl.util.io.JarUtils; import org.jackhuang.hmcl.util.io.NetworkUtils; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -34,6 +35,7 @@ import java.util.logging.Level; import static org.jackhuang.hmcl.util.Lang.mapOf; import static org.jackhuang.hmcl.util.Lang.thread; +import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class MicrosoftAuthenticationServer extends NanoHTTPD implements MicrosoftService.OAuthSession { private final int port; @@ -69,7 +71,8 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi String html; try { - html = IOUtils.readFullyAsString(MicrosoftAuthenticationServer.class.getResourceAsStream("/assets/microsoft_auth.html")); + html = IOUtils.readFullyAsString(MicrosoftAuthenticationServer.class.getResourceAsStream("/assets/microsoft_auth.html"), StandardCharsets.UTF_8) + .replace("%close-page%", i18n("account.methods.microsoft.close_page")); } catch (IOException e) { Logging.LOG.log(Level.SEVERE, "Failed to load html"); return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, MIME_HTML, ""); @@ -82,7 +85,7 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi Logging.LOG.log(Level.SEVERE, "Failed to sleep for 1 second"); } }); - return newFixedLengthResponse(html); + return newFixedLengthResponse(Response.Status.OK, "text/html; charset=UTF-8", html); } public static class Factory implements MicrosoftService.OAuthCallback { diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index ea6ca2f66..3effb4dc1 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -65,6 +65,10 @@ account.manage=Account List account.methods=Login Type account.methods.authlib_injector=authlib-injector account.methods.microsoft=Microsoft Account +account.methods.microsoft.close_page=Microsoft account authorization has been finished. There are some remaining logging-in steps to be finished later. You can close this page right now. +account.methods.microsoft.logging_in=Logging in... +account.methods.microsoft.manual=You should finish authorization in the newly opened browser window. If the browser window failed to show, you can click here to copy the URL, and manually open it in your browser. +account.methods.microsoft.waiting_browser=Waiting for authorization in opened browser window... account.methods.offline=Offline account.methods.yggdrasil=Mojang account.missing=No Account diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index c10223b42..2be487ae1 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -66,6 +66,10 @@ account.manage=账户列表 account.methods=登录方式 account.methods.authlib_injector=外置登录 (authlib-injector) account.methods.microsoft=微软登录 +account.methods.microsoft.close_page=已完成微软账号授权,接下来启动器还需要完成剩余登录步骤。你已经可以关闭本页面了。 +account.methods.microsoft.logging_in=登录中... +account.methods.microsoft.manual=您需要在新打开的浏览器窗口中完成登录。若页面未能打开,您可以点击此处复制链接,并手动在浏览器中打开网页。 +account.methods.microsoft.waiting_browser=等待在新打开的浏览器窗口中完成登录... account.methods.offline=离线模式 account.methods.yggdrasil=Mojang 账号 account.missing=没有游戏账户 diff --git a/HMCL/src/main/resources/assets/microsoft_auth.html b/HMCL/src/main/resources/assets/microsoft_auth.html index ae0ca3da9..4c6df8a53 100644 --- a/HMCL/src/main/resources/assets/microsoft_auth.html +++ b/HMCL/src/main/resources/assets/microsoft_auth.html @@ -16,22 +16,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . --> - + - + Hello Minecraft! Launcher
- 你可以关闭本标签页了 + %close-page%
- - - \ No newline at end of file diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java index ddddda02e..08a211c50 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/HttpRequest.java @@ -57,10 +57,6 @@ public abstract class HttpRequest { return header("Authorization", token); } - public HttpRequest contentType(String contentType) { - return header("Content-Type", contentType); - } - public HttpRequest header(String key, String value) { headers.put(key, value); return this; @@ -109,6 +105,11 @@ public abstract class HttpRequest { super(url, "POST"); } + public HttpPostRequest contentType(String contentType) { + headers.put("Content-Type", contentType); + return this; + } + public HttpPostRequest json(Object payload) throws JsonParseException { return string(payload instanceof String ? (String) payload : GSON.toJson(payload), "application/json"); }