Улучшить UI регистрации и связанные сценарии

This commit is contained in:
AidarKC
2026-11-08 18:04:06 +03:00
parent 9405f28525
commit 4068465ee6
66 changed files with 842 additions and 221 deletions
@@ -74,7 +74,7 @@ public final class FreeRegistrationApiBootstrap {
case "GetNamespaces" -> {
out.put("namespaces",w.listNamespaces().stream().map(ns->Map.of(
"name",ns.namespace(), "type",ns.type(), "minLocalLength",ns.minLoginLength(),
"registrationFeeLamports",ns.priceLamports(), "defaultServerLogin",ns.serverLogin()==null?"":ns.serverLogin()
"registrationFeeLamports",ns.priceLamports(), "currencyCode",ns.currencyCode(), "defaultServerLogin",ns.serverLogin()==null?"":ns.serverLogin()
)).toList());
}
case "CheckRegistrationLogin" -> {
@@ -83,6 +83,7 @@ public final class FreeRegistrationApiBootstrap {
out.put("namespaceType",info.namespaceType());
out.put("minLocalLength",info.minLocalLength());
out.put("registrationFeeLamports",info.registrationFeeLamports());
out.put("currencyCode",info.currencyCode());
}
case "CheckRegistrationEmail" -> {
var check=w.checkEmail(req.getEmail());
@@ -15,9 +15,9 @@ import java.util.concurrent.ConcurrentHashMap;
/** Внутренний state machine публичных операций регистрации v2. */
public final class FreeRegistrationWorkflow {
public record NamespaceInfo(String namespace, int type, int minLoginLength, String priceLamports, String serverLogin) {}
public record NamespaceInfo(String namespace, int type, int minLoginLength, String priceLamports, int currencyCode, String serverLogin) {}
public record Availability(boolean nameFree, boolean emailHashFree) {}
public record LoginCheck(boolean loginAvailable, int namespaceType, int minLocalLength, String registrationFeeLamports) {}
public record LoginCheck(boolean loginAvailable, int namespaceType, int minLocalLength, String registrationFeeLamports, int currencyCode) {}
public record EmailCheck(boolean emailAvailable, String emailStatus) {}
public record Started(String challengeId, long expiresAtMs) {}
public record Completed(String fullLogin, String dataItemId, String state, boolean alreadyImported) {}
@@ -93,11 +93,11 @@ public final class FreeRegistrationWorkflow {
List<NamespaceInfo> result = new ArrayList<>();
try (Connection c = DbController.getInstance().getConnection();
PreparedStatement ps = c.prepareStatement("""
SELECT namespace,namespace_type,min_localpart_len,registration_fee_lamports,default_server_login
SELECT namespace,namespace_type,min_localpart_len,registration_fee_lamports,currency_code,default_server_login
FROM shine_namespace_current ORDER BY namespace
"""); ResultSet rs = ps.executeQuery()) {
while (rs.next()) result.add(new NamespaceInfo(rs.getString(1),rs.getInt(2),rs.getInt(3),
rs.getString(4),rs.getString(5)));
rs.getString(4),rs.getInt(5),rs.getString(6)));
}
return List.copyOf(result);
}
@@ -105,18 +105,19 @@ public final class FreeRegistrationWorkflow {
FreeRegistrationCertificateV1.validateLogin(login);
String namespace=login.substring(login.indexOf('@')+1);
try (Connection c=DbController.getInstance().getConnection()) {
int type, minimum; String fee;
try (PreparedStatement p=c.prepareStatement("SELECT namespace_type,min_localpart_len,registration_fee_lamports FROM shine_namespace_current WHERE namespace=?")) {
int type, minimum, currencyCode; String fee;
try (PreparedStatement p=c.prepareStatement("SELECT namespace_type,min_localpart_len,registration_fee_lamports,currency_code FROM shine_namespace_current WHERE namespace=?")) {
p.setString(1,namespace);
try (ResultSet rs=p.executeQuery()) {
if (!rs.next()) throw new IllegalArgumentException("Namespace is unavailable");
type=rs.getInt(1); minimum=rs.getInt(2); fee=rs.getString(3);
type=rs.getInt(1); minimum=rs.getInt(2); fee=rs.getString(3); currencyCode=rs.getInt(4);
if (currencyCode != 1) throw new IllegalStateException("Unsupported namespace currency");
if (login.indexOf('@') < minimum) throw new IllegalArgumentException("Login shorter than namespace minimum");
}
}
try (PreparedStatement p=c.prepareStatement("SELECT 1 FROM user_identity_current WHERE normalized_login=?")) {
p.setString(1, login.toLowerCase(java.util.Locale.ROOT));
try (ResultSet rs=p.executeQuery()) { return new LoginCheck(!rs.next(),type,minimum,fee); }
try (ResultSet rs=p.executeQuery()) { return new LoginCheck(!rs.next(),type,minimum,fee,currencyCode); }
}
}
}