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
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.RegistrationManager
;
11 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.CaptchaRequiredException
;
13 import java
.io
.IOException
;
15 public class RegisterCommand
implements RegistrationCommand
{
18 public String
getName() {
23 public void attachToSubparser(final Subparser subparser
) {
24 subparser
.help("Register a phone number with SMS or voice verification.");
25 subparser
.addArgument("-v", "--voice")
26 .help("The verification should be done over voice, not SMS.")
27 .action(Arguments
.storeTrue());
28 subparser
.addArgument("--captcha")
29 .help("The captcha token, required if registration failed with a captcha required error.");
33 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
34 final boolean voiceVerification
= Boolean
.TRUE
.equals(ns
.getBoolean("voice"));
35 final var captchaString
= ns
.getString("captcha");
36 final var captcha
= captchaString
== null ?
null : captchaString
.replace("signalcaptcha://", "");
39 m
.register(voiceVerification
, captcha
);
40 } catch (CaptchaRequiredException e
) {
42 if (captcha
== null) {
43 message
= "Captcha required for verification, use --captcha CAPTCHA\n"
44 + "To get the token, go to https://signalcaptchas.org/registration/generate.html\n"
45 + "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n"
46 + "Everything after signalcaptcha:// is the captcha token.";
48 message
= "Invalid captcha given.";
50 throw new UserErrorException(message
);
51 } catch (IOException e
) {
52 throw new IOErrorException("Request verify error: " + e
.getMessage(), e
);