Add register parameter to force reregistration

This commit is contained in:
AsamK 2024-02-27 18:12:43 +01:00
parent 2e4cd0eddc
commit 2424fc1f53
6 changed files with 31 additions and 14 deletions

View file

@ -37,14 +37,18 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
.action(Arguments.storeTrue());
subparser.addArgument("--captcha")
.help("The captcha token, required if registration failed with a captcha required error.");
subparser.addArgument("--reregister")
.action(Arguments.storeTrue())
.help("Register even if account is already registered");
}
@Override
public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException {
final boolean voiceVerification = Boolean.TRUE.equals(ns.getBoolean("voice"));
final var captcha = ns.getString("captcha");
final var reregister = Boolean.TRUE.equals(ns.getBoolean("reregister"));
register(m, voiceVerification, captcha);
register(m, voiceVerification, captcha, reregister);
}
@Override
@ -61,14 +65,14 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
public void handleCommand(
final RegistrationParams request, final RegistrationManager m, final JsonWriter jsonWriter
) throws CommandException {
register(m, Boolean.TRUE.equals(request.voice()), request.captcha());
register(m, Boolean.TRUE.equals(request.voice()), request.captcha(), Boolean.TRUE.equals(request.reregister()));
}
private void register(
final RegistrationManager m, final boolean voiceVerification, final String captcha
final RegistrationManager m, final boolean voiceVerification, final String captcha, final boolean reregister
) throws CommandException {
try {
m.register(voiceVerification, captcha);
m.register(voiceVerification, captcha, reregister);
} catch (RateLimitException e) {
final var message = CommandUtil.getRateLimitMessage(e);
throw new RateLimitErrorException(message, e);
@ -89,5 +93,5 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
}
}
public record RegistrationParams(Boolean voice, String captcha) {}
public record RegistrationParams(Boolean voice, String captcha, Boolean reregister) {}
}

View file

@ -27,8 +27,11 @@ public class DbusRegistrationManagerImpl implements RegistrationManager {
@Override
public void register(
final boolean voiceVerification, final String captcha
final boolean voiceVerification, final String captcha, final boolean forceRegister
) throws IOException, CaptchaRequiredException {
if (forceRegister) {
throw new UnsupportedOperationException();
}
if (captcha == null) {
signalControl.register(number, voiceVerification);
} else {

View file

@ -63,7 +63,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
"Invalid account (phone number), make sure you include the country code.");
}
try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) {
registrationManager.register(voiceVerification, captcha);
registrationManager.register(voiceVerification, captcha, false);
} catch (RateLimitException e) {
String message = "Rate limit reached";
throw new SignalControl.Error.Failure(message);