1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
4 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
5 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
7 import org
.asamk
.signal
.OutputWriter
;
8 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
9 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
10 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
11 import org
.asamk
.signal
.manager
.RegistrationManager
;
12 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.CaptchaRequiredException
;
14 import java
.io
.IOException
;
16 public class RegisterCommand
implements RegistrationCommand
{
18 public RegisterCommand(final OutputWriter outputWriter
) {
21 public static void attachToSubparser(final Subparser subparser
) {
22 subparser
.help("Register a phone number with SMS or voice verification.");
23 subparser
.addArgument("-v", "--voice")
24 .help("The verification should be done over voice, not SMS.")
25 .action(Arguments
.storeTrue());
26 subparser
.addArgument("--captcha")
27 .help("The captcha token, required if registration failed with a captcha required error.");
31 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
32 final boolean voiceVerification
= ns
.getBoolean("voice");
33 final var captchaString
= ns
.getString("captcha");
34 final var captcha
= captchaString
== null ?
null : captchaString
.replace("signalcaptcha://", "");
37 m
.register(voiceVerification
, captcha
);
38 } catch (CaptchaRequiredException e
) {
40 if (captcha
== null) {
41 message
= "Captcha required for verification, use --captcha CAPTCHA\n"
42 + "To get the token, go to https://signalcaptchas.org/registration/generate.html\n"
43 + "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n"
44 + "Everything after signalcaptcha:// is the captcha token.";
46 message
= "Invalid captcha given.";
48 throw new UserErrorException(message
);
49 } catch (IOException e
) {
50 throw new IOErrorException("Request verify error: " + e
.getMessage());