add registration manager (change password + delete account)
This commit is contained in:
parent
268bef4433
commit
79eebe68e2
|
@ -17,6 +17,7 @@ import im.conversations.android.xmpp.manager.PepManager;
|
||||||
import im.conversations.android.xmpp.manager.PresenceManager;
|
import im.conversations.android.xmpp.manager.PresenceManager;
|
||||||
import im.conversations.android.xmpp.manager.PubSubManager;
|
import im.conversations.android.xmpp.manager.PubSubManager;
|
||||||
import im.conversations.android.xmpp.manager.ReceiptManager;
|
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.RosterManager;
|
||||||
import im.conversations.android.xmpp.manager.StanzaIdManager;
|
import im.conversations.android.xmpp.manager.StanzaIdManager;
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ public final class Managers {
|
||||||
.put(PresenceManager.class, new PresenceManager(context, connection))
|
.put(PresenceManager.class, new PresenceManager(context, connection))
|
||||||
.put(PubSubManager.class, new PubSubManager(context, connection))
|
.put(PubSubManager.class, new PubSubManager(context, connection))
|
||||||
.put(ReceiptManager.class, new ReceiptManager(context, connection))
|
.put(ReceiptManager.class, new ReceiptManager(context, connection))
|
||||||
|
.put(RegistrationManager.class, new RegistrationManager(context, connection))
|
||||||
.put(RosterManager.class, new RosterManager(context, connection))
|
.put(RosterManager.class, new RosterManager(context, connection))
|
||||||
.put(StanzaIdManager.class, new StanzaIdManager(context, connection))
|
.put(StanzaIdManager.class, new StanzaIdManager(context, connection))
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,4 +9,12 @@ public class Register extends Extension {
|
||||||
public Register() {
|
public Register() {
|
||||||
super(Register.class);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue