add registration manager (change password + delete account)

This commit is contained in:
Daniel Gultsch 2023-02-14 10:20:40 +01:00
parent 268bef4433
commit 79eebe68e2
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
6 changed files with 83 additions and 0 deletions

View file

@ -17,6 +17,7 @@ import im.conversations.android.xmpp.manager.PepManager;
import im.conversations.android.xmpp.manager.PresenceManager;
import im.conversations.android.xmpp.manager.PubSubManager;
import im.conversations.android.xmpp.manager.ReceiptManager;
import im.conversations.android.xmpp.manager.RegistrationManager;
import im.conversations.android.xmpp.manager.RosterManager;
import im.conversations.android.xmpp.manager.StanzaIdManager;
@ -40,6 +41,7 @@ public final class Managers {
.put(PresenceManager.class, new PresenceManager(context, connection))
.put(PubSubManager.class, new PubSubManager(context, connection))
.put(ReceiptManager.class, new ReceiptManager(context, connection))
.put(RegistrationManager.class, new RegistrationManager(context, connection))
.put(RosterManager.class, new RosterManager(context, connection))
.put(StanzaIdManager.class, new StanzaIdManager(context, connection))
.build();

View file

@ -0,0 +1,41 @@
package im.conversations.android.xmpp.manager;
import android.content.Context;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import im.conversations.android.xmpp.XmppConnection;
import im.conversations.android.xmpp.model.register.Register;
import im.conversations.android.xmpp.model.register.Remove;
import im.conversations.android.xmpp.model.stanza.Iq;
public class RegistrationManager extends AbstractManager {
public RegistrationManager(Context context, XmppConnection connection) {
super(context, connection);
}
public ListenableFuture<Void> setPassword(final String password) {
final var account = getAccount();
final var iq = new Iq(Iq.Type.SET);
final var register = iq.addExtension(new Register());
register.addUsername(account.address.getEscapedLocal());
register.addPassword(password);
return Futures.transform(
connection.sendIqPacket(iq), r -> null, MoreExecutors.directExecutor());
}
public ListenableFuture<Void> unregister() {
final var iq = new Iq(Iq.Type.SET);
final var register = iq.addExtension(new Register());
register.addExtension(new Remove());
return Futures.transform(
connection.sendIqPacket(iq), r -> null, MoreExecutors.directExecutor());
}
// TODO support registration
// 3 possible responses:
// 1) username + password
// 2) Captcha as shown here: https://xmpp.org/extensions/xep-0158.html#register
// 3) Redirection as show here: https://xmpp.org/extensions/xep-0077.html#redirect
}

View file

@ -0,0 +1,10 @@
package im.conversations.android.xmpp.model.register;
import im.conversations.android.xmpp.model.Extension;
public class Password extends Extension {
public Password() {
super(Password.class);
}
}

View file

@ -9,4 +9,12 @@ public class Register extends Extension {
public Register() {
super(Register.class);
}
public void addUsername(final String username) {
this.addExtension(new Username()).setContent(username);
}
public void addPassword(final String password) {
this.addExtension(new Password()).setContent(password);
}
}

View file

@ -0,0 +1,10 @@
package im.conversations.android.xmpp.model.register;
import im.conversations.android.xmpp.model.Extension;
public class Remove extends Extension {
public Remove() {
super(Remove.class);
}
}

View file

@ -0,0 +1,12 @@
package im.conversations.android.xmpp.model.register;
import im.conversations.android.annotation.XmlElement;
import im.conversations.android.xmpp.model.Extension;
@XmlElement
public class Username extends Extension {
public Username() {
super(Username.class);
}
}