Refactor register and verify

This commit is contained in:
AsamK 2021-01-10 17:07:06 +01:00
parent 6c8a1ff3d3
commit e74be0c345
33 changed files with 405 additions and 362 deletions

View file

@ -23,10 +23,6 @@ public class AddDeviceCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
m.addDeviceLink(new URI(ns.getString("uri")));
return 0;

View file

@ -21,11 +21,6 @@ public class BlockCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
for (String contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, true);

View file

@ -35,10 +35,6 @@ public class DaemonCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
DBusConnection conn = null;
try {
try {

View file

@ -28,11 +28,6 @@ public class GetUserStatusCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
// Setup the json object mapper
ObjectMapper jsonProcessor = new ObjectMapper();
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

View file

@ -29,11 +29,6 @@ public class JoinGroupCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
final GroupInviteLinkUrl linkUrl;
String uri = ns.getString("uri");
try {

View file

@ -16,10 +16,6 @@ public class ListContactsCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
List<ContactInfo> contacts = m.getContacts();
for (ContactInfo c : contacts) {
System.out.println(String.format("Number: %s Name: %s Blocked: %b", c.number, c.name, c.blocked));

View file

@ -18,10 +18,6 @@ public class ListDevicesCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
List<DeviceInfo> devices = m.getLinkedDevices();
for (DeviceInfo d : devices) {

View file

@ -64,11 +64,6 @@ public class ListGroupsCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
List<GroupInfo> groups = m.getGroups();
boolean detailed = ns.getBoolean("detailed");

View file

@ -30,10 +30,6 @@ public class ListIdentitiesCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
if (ns.get("number") == null) {
for (IdentityInfo identity : m.getIdentities()) {
printIdentityFingerprint(m, identity);

View file

@ -31,11 +31,6 @@ public class QuitGroupCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
final GroupId groupId = Util.decodeGroupId(ns.getString("group"));
final Pair<Long, List<SendMessageResult>> results = m.sendQuitGroupMessage(groupId);

View file

@ -146,10 +146,6 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
double timeout = 5;
if (ns.getDouble("timeout") != null) {
timeout = ns.getDouble("timeout");

View file

@ -4,12 +4,12 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.RegistrationManager;
import org.whispersystems.signalservice.api.push.exceptions.CaptchaRequiredException;
import java.io.IOException;
public class RegisterCommand implements LocalCommand {
public class RegisterCommand implements RegistrationCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
@ -21,7 +21,7 @@ public class RegisterCommand implements LocalCommand {
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
public int handleCommand(final Namespace ns, final RegistrationManager m) {
try {
final boolean voiceVerification = ns.getBoolean("voice");
final String captcha = ns.getString("captcha");

View file

@ -0,0 +1,10 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace;
import org.asamk.signal.manager.RegistrationManager;
public interface RegistrationCommand extends Command {
int handleCommand(Namespace ns, RegistrationManager m);
}

View file

@ -19,10 +19,6 @@ public class RemoveDeviceCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
int deviceId = ns.getInt("deviceId");
m.removeLinkedDevices(deviceId);

View file

@ -17,10 +17,6 @@ public class RemovePinCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
m.setRegistrationLockPin(Optional.absent());
return 0;

View file

@ -17,10 +17,6 @@ public class SendContactsCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
m.sendContacts();
return 0;

View file

@ -47,11 +47,6 @@ public class SendReactionCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
if ((ns.getList("recipient") == null || ns.getList("recipient").size() == 0) && ns.getString("group") == null) {
System.err.println("No recipients given");
System.err.println("Aborting sending.");

View file

@ -19,10 +19,6 @@ public class SetPinCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
String registrationLockPin = ns.getString("registrationLockPin");
m.setRegistrationLockPin(Optional.of(registrationLockPin));

View file

@ -27,10 +27,6 @@ public class TrustCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
String number = ns.getString("number");
if (ns.getBoolean("trust_all_known_keys")) {
boolean res = m.trustIdentityAllKeys(number);

View file

@ -21,11 +21,6 @@ public class UnblockCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
for (String contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, false);

View file

@ -16,10 +16,6 @@ public class UnregisterCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
m.unregister();
return 0;

View file

@ -16,10 +16,6 @@ public class UpdateAccountCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
try {
m.updateAccountAttributes();
return 0;

View file

@ -23,11 +23,6 @@ public class UpdateContactCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
String number = ns.getString("number");
String name = ns.getString("name");

View file

@ -25,11 +25,6 @@ public class UpdateProfileCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
String name = ns.getString("name");
String avatarPath = ns.getString("avatar");
boolean removeAvatar = ns.getBoolean("remove_avatar");

View file

@ -3,14 +3,14 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.RegistrationManager;
import org.whispersystems.signalservice.api.KeyBackupServicePinException;
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException;
import org.whispersystems.signalservice.internal.push.LockedException;
import java.io.IOException;
public class VerifyCommand implements LocalCommand {
public class VerifyCommand implements RegistrationCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
@ -19,11 +19,7 @@ public class VerifyCommand implements LocalCommand {
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (m.isRegistered()) {
System.err.println("User registration is already verified");
return 1;
}
public int handleCommand(final Namespace ns, final RegistrationManager m) {
try {
String verificationCode = ns.getString("verificationCode");
String pin = ns.getString("pin");