mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-14 06:17:47 -04:00
Merge branch 'javafx' of https://github.com/huanghongxun/HMCL into javafx
This commit is contained in:
commit
8108f11c45
@ -114,7 +114,7 @@ public class AddAccountPane extends StackPane {
|
||||
cboServers.visibleProperty().bind(loginType.isEqualTo(Accounts.FACTORY_AUTHLIB_INJECTOR));
|
||||
lblInjectorServer.visibleProperty().bind(cboServers.visibleProperty());
|
||||
|
||||
txtUsername.getValidators().add(new Validator(i18n("input.email"), str -> !txtPassword.isVisible() || str.contains("@")));
|
||||
txtUsername.getValidators().add(new Validator(i18n("input.email"), this::validateUsername));
|
||||
|
||||
btnAccept.disableProperty().bind(Bindings.createBooleanBinding(
|
||||
() -> !( // consider the opposite situation: input is valid
|
||||
@ -123,9 +123,9 @@ public class AddAccountPane extends StackPane {
|
||||
(!txtPassword.isVisible() || txtPassword.validate()) &&
|
||||
(!cboServers.isVisible() || cboServers.getSelectionModel().getSelectedItem() != null)
|
||||
),
|
||||
txtUsername.textProperty(),
|
||||
txtPassword.textProperty(), txtPassword.visibleProperty(),
|
||||
cboServers.getSelectionModel().selectedItemProperty(), cboServers.visibleProperty()));
|
||||
txtUsername.textProperty(), txtPassword.textProperty(),
|
||||
loginType, cboServers.getSelectionModel().selectedItemProperty(),
|
||||
txtPassword.visibleProperty(), cboServers.visibleProperty()));
|
||||
|
||||
// authlib-injector links
|
||||
links.bind(BindingMapping.of(cboServers.getSelectionModel().selectedItemProperty())
|
||||
@ -135,6 +135,20 @@ public class AddAccountPane extends StackPane {
|
||||
linksContainer.visibleProperty().bind(cboServers.visibleProperty());
|
||||
}
|
||||
|
||||
private boolean validateUsername(String username) {
|
||||
AccountFactory<?> loginType = cboType.getSelectionModel().getSelectedItem();
|
||||
if (loginType == Accounts.FACTORY_OFFLINE) {
|
||||
return true;
|
||||
} else if (loginType == Accounts.FACTORY_AUTHLIB_INJECTOR) {
|
||||
AuthlibInjectorServer server = cboServers.getSelectionModel().getSelectedItem();
|
||||
if (server != null && server.isNonEmailLogin()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return username.contains("@");
|
||||
}
|
||||
|
||||
private static final String[] ALLOWED_LINKS = { "register" };
|
||||
|
||||
public static List<Hyperlink> createHyperlinks(AuthlibInjectorServer server) {
|
||||
|
@ -110,6 +110,7 @@ public class AuthlibInjectorServer implements Observable {
|
||||
@Nullable
|
||||
private transient String name;
|
||||
private transient Map<String, String> links = emptyMap();
|
||||
private transient boolean nonEmailLogin;
|
||||
|
||||
private transient boolean metadataRefreshed;
|
||||
private final transient ObservableHelper helper = new ObservableHelper(this);
|
||||
@ -145,6 +146,10 @@ public class AuthlibInjectorServer implements Observable {
|
||||
return links;
|
||||
}
|
||||
|
||||
public boolean isNonEmailLogin() {
|
||||
return nonEmailLogin;
|
||||
}
|
||||
|
||||
public String fetchMetadataResponse() throws IOException {
|
||||
if (metadataResponse == null || !metadataRefreshed) {
|
||||
refreshMetadata();
|
||||
@ -194,6 +199,9 @@ public class AuthlibInjectorServer implements Observable {
|
||||
return converted;
|
||||
})
|
||||
.orElse(emptyMap());
|
||||
this.nonEmailLogin = metaObject.flatMap(meta -> tryCast(meta.get("feature.non_email_login"), JsonPrimitive.class))
|
||||
.map(it -> it.getAsBoolean())
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user