mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Add register parameter to force reregistration
This commit is contained in:
parent
2e4cd0eddc
commit
2424fc1f53
6 changed files with 31 additions and 14 deletions
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
|||
public interface RegistrationManager extends Closeable {
|
||||
|
||||
void register(
|
||||
boolean voiceVerification, String captcha
|
||||
boolean voiceVerification, String captcha, final boolean forceRegister
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException;
|
||||
|
||||
void verifyAccount(
|
||||
|
|
|
@ -104,7 +104,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
|
||||
@Override
|
||||
public void register(
|
||||
boolean voiceVerification, String captcha
|
||||
boolean voiceVerification, String captcha, final boolean forceRegister
|
||||
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
|
||||
if (account.isRegistered()
|
||||
&& account.getServiceEnvironment() != null
|
||||
|
@ -113,12 +113,18 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
}
|
||||
|
||||
try {
|
||||
final var recoveryPassword = account.getRecoveryPassword();
|
||||
if (recoveryPassword != null && account.isPrimaryDevice() && attemptReregisterAccount(recoveryPassword)) {
|
||||
return;
|
||||
if (!forceRegister) {
|
||||
if (account.isRegistered()) {
|
||||
throw new IOException("Account is already registered");
|
||||
}
|
||||
|
||||
if (account.getAci() != null && attemptReactivateAccount()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (account.getAci() != null && attemptReactivateAccount()) {
|
||||
final var recoveryPassword = account.getRecoveryPassword();
|
||||
if (recoveryPassword != null && account.isPrimaryDevice() && attemptReregisterAccount(recoveryPassword)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -128,6 +134,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
|||
voiceVerification,
|
||||
captcha);
|
||||
NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
|
||||
account.setRegistered(false);
|
||||
} catch (DeprecatedVersionException e) {
|
||||
logger.debug("Signal-Server returned deprecated version exception", e);
|
||||
throw e;
|
||||
|
|
|
@ -102,12 +102,15 @@ If the account was deleted (with --delete-account) it cannot be reactivated.
|
|||
The verification should be done over voice, not SMS.
|
||||
Voice verification only works if an SMS verification has been attempted before.
|
||||
|
||||
*--captcha*::
|
||||
*--captcha* CAPTCHA::
|
||||
The captcha token, required if registration failed with a captcha required error.
|
||||
To get the token, go to https://signalcaptchas.org/registration/generate.html
|
||||
For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html
|
||||
After solving the captcha, right-click on the "Open Signal" link and copy the link.
|
||||
|
||||
*--reregister*::
|
||||
Register even if account is already registered.
|
||||
|
||||
=== verify
|
||||
|
||||
Verify the number using the code received via SMS or voice.
|
||||
|
|
|
@ -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) {}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue