summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api/plugins/xep_0077.rst47
-rw-r--r--slixmpp/plugins/xep_0077/register.py21
-rw-r--r--tests/test_stream_xep_0077.py4
3 files changed, 60 insertions, 12 deletions
diff --git a/docs/api/plugins/xep_0077.rst b/docs/api/plugins/xep_0077.rst
index 725c16b0..33c433e0 100644
--- a/docs/api/plugins/xep_0077.rst
+++ b/docs/api/plugins/xep_0077.rst
@@ -8,6 +8,53 @@ XEP-0077: In-Band Registration
:members:
:exclude-members: session_bind, plugin_init, plugin_end
+Internal APi methods
+--------------------
+
+The API here is made to allow components to manage registered users.
+The default handlers make use of the plugin options and store users
+in memory.
+
+.. glossary::
+
+ user_get
+ - **jid**: unused
+ - **node**: unused
+ - **ifrom**: who the request is coming from
+ - **args**: :class:`~.Iq` registration request.
+ - **returns**: ``dict`` containing user data or None.
+
+ Get user data for a user.
+
+ user_validate
+ - **jid**: unused
+ - **node**: unused
+ - **ifrom**: who the request is coming from
+ - **args**: :class:`~.Iq` registration request, 'register' payload.
+ - **raises**: ValueError if some fields are invalid
+
+ Validate form fields and save user data.
+
+ user_remove
+ - **jid**: unused
+ - **node**: unused
+ - **ifrom**: who the request is coming from
+ - **args**: :class:`~.Iq` registration removal request.
+ - **raises**: KeyError if the user is not found.
+
+ Remove a user from the store.
+
+ make_registration_form
+ - **jid**: unused
+ - **node**: unused
+ - **ifrom**: who the request is coming from
+ - **args**: :class:`~.Iq` registration request.
+ - **raises**: KeyError if the user is not found.
+
+ Return an :class:`~.Iq` reply for the request, with a form and
+ options set. By default, use ``form_fields`` and ``form_instructions``
+ plugin config options.
+
Stanza elements
---------------
diff --git a/slixmpp/plugins/xep_0077/register.py b/slixmpp/plugins/xep_0077/register.py
index 1850b2c9..c5d1fa27 100644
--- a/slixmpp/plugins/xep_0077/register.py
+++ b/slixmpp/plugins/xep_0077/register.py
@@ -29,7 +29,7 @@ class XEP_0077(BasePlugin):
user_register -- After succesful validation and add to the user store
in api["user_validate"]
user_unregister -- After succesful user removal in api["user_remove"]
-
+
Config:
::
@@ -38,7 +38,7 @@ class XEP_0077(BasePlugin):
in case api["make_registration_form"] is not overriden.
API:
-
+
::
user_get(jid, node, ifrom, iq)
@@ -102,14 +102,13 @@ class XEP_0077(BasePlugin):
def _user_get(self, jid, node, ifrom, iq):
return self._user_store.get(iq["from"].bare)
-
+
def _user_remove(self, jid, node, ifrom, iq):
return self._user_store.pop(iq["from"].bare)
- def _make_registration_form(self, jid, node, ifrom, iq: Iq):
+ async def _make_registration_form(self, jid, node, ifrom, iq: Iq):
reg = iq["register"]
- user = self.api["user_get"](None, None, None, iq)
-
+ user = await self.api["user_get"](None, None, iq['from'], iq)
if user is None:
user = {}
@@ -135,11 +134,11 @@ class XEP_0077(BasePlugin):
async def _handle_registration(self, iq: Iq):
if iq["type"] == "get":
- self._send_form(iq)
+ await self._send_form(iq)
elif iq["type"] == "set":
if iq["register"]["remove"]:
try:
- self.api["user_remove"](None, None, iq["from"], iq)
+ await self.api["user_remove"](None, None, iq["from"], iq)
except KeyError:
_send_error(
iq,
@@ -168,7 +167,7 @@ class XEP_0077(BasePlugin):
return
try:
- self.api["user_validate"](None, None, iq["from"], iq["register"])
+ await self.api["user_validate"](None, None, iq["from"], iq["register"])
except ValueError as e:
_send_error(
iq,
@@ -182,8 +181,8 @@ class XEP_0077(BasePlugin):
reply.send()
self.xmpp.event("user_register", iq)
- def _send_form(self, iq):
- reply = self.api["make_registration_form"](None, None, iq["from"], iq)
+ async def _send_form(self, iq):
+ reply = await self.api["make_registration_form"](None, None, iq["from"], iq)
reply.send()
def _force_registration(self, event):
diff --git a/tests/test_stream_xep_0077.py b/tests/test_stream_xep_0077.py
index c47c4de5..69fc9255 100644
--- a/tests/test_stream_xep_0077.py
+++ b/tests/test_stream_xep_0077.py
@@ -91,7 +91,9 @@ class TestRegistration(SlixTest):
self.send("<iq type='result' id='reg2' from='shakespeare.lit' to='bill@shakespeare.lit/globe'/>")
pseudo_iq = self.xmpp.Iq()
pseudo_iq["from"] = "bill@shakespeare.lit/globe"
- user = self.xmpp["xep_0077"].api["user_get"](None, None, None, pseudo_iq)
+ fut = self.xmpp.wrap(self.xmpp["xep_0077"].api["user_get"](None, None, None, pseudo_iq))
+ self.run_coro(fut)
+ user = fut.result()
self.assertEqual(user["username"], "bill")
self.assertEqual(user["password"], "Calliope")
self.recv(