fix: mess code in Microsoft login page. Closes #981.

This commit is contained in:
huanghongxun 2021-08-28 16:27:27 +08:00
parent 96e6554b37
commit cc868656a8
5 changed files with 21 additions and 14 deletions

View File

@ -27,6 +27,7 @@ import org.jackhuang.hmcl.util.io.JarUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils; import org.jackhuang.hmcl.util.io.NetworkUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; 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.mapOf;
import static org.jackhuang.hmcl.util.Lang.thread; 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 { public final class MicrosoftAuthenticationServer extends NanoHTTPD implements MicrosoftService.OAuthSession {
private final int port; private final int port;
@ -69,7 +71,8 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi
String html; String html;
try { 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) { } catch (IOException e) {
Logging.LOG.log(Level.SEVERE, "Failed to load html"); Logging.LOG.log(Level.SEVERE, "Failed to load html");
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, MIME_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"); 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 { public static class Factory implements MicrosoftService.OAuthCallback {

View File

@ -65,6 +65,10 @@ account.manage=Account List
account.methods=Login Type account.methods=Login Type
account.methods.authlib_injector=authlib-injector account.methods.authlib_injector=authlib-injector
account.methods.microsoft=Microsoft Account 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.offline=Offline
account.methods.yggdrasil=Mojang account.methods.yggdrasil=Mojang
account.missing=No Account account.missing=No Account

View File

@ -66,6 +66,10 @@ account.manage=账户列表
account.methods=登录方式 account.methods=登录方式
account.methods.authlib_injector=外置登录 (authlib-injector) account.methods.authlib_injector=外置登录 (authlib-injector)
account.methods.microsoft=微软登录 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.offline=离线模式
account.methods.yggdrasil=Mojang 账号 account.methods.yggdrasil=Mojang 账号
account.missing=没有游戏账户 account.missing=没有游戏账户

View File

@ -16,22 +16,17 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello Minecraft! Launcher</title> <title>Hello Minecraft! Launcher</title>
</head> </head>
<body> <body>
<div> <div>
你可以关闭本标签页了 %close-page%
</div> </div>
<script>
window.close()
</script>
</body> </body>
</html> </html>

View File

@ -57,10 +57,6 @@ public abstract class HttpRequest {
return header("Authorization", token); return header("Authorization", token);
} }
public HttpRequest contentType(String contentType) {
return header("Content-Type", contentType);
}
public HttpRequest header(String key, String value) { public HttpRequest header(String key, String value) {
headers.put(key, value); headers.put(key, value);
return this; return this;
@ -109,6 +105,11 @@ public abstract class HttpRequest {
super(url, "POST"); super(url, "POST");
} }
public HttpPostRequest contentType(String contentType) {
headers.put("Content-Type", contentType);
return this;
}
public HttpPostRequest json(Object payload) throws JsonParseException { public HttpPostRequest json(Object payload) throws JsonParseException {
return string(payload instanceof String ? (String) payload : GSON.toJson(payload), "application/json"); return string(payload instanceof String ? (String) payload : GSON.toJson(payload), "application/json");
} }