Skip to content

Commit ebeb7bd

Browse files
committed
Setting full name and email for xmpp account
1 parent 3267374 commit ebeb7bd

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

conversejs/register.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ class RegisterBot(sleekxmpp.ClientXMPP):
4646
workflows will need to check for data forms, etc.
4747
"""
4848

49-
def __init__(self, jid, password):
49+
def __init__(self, jid, password, name=None, email=None):
5050
sleekxmpp.ClientXMPP.__init__(self, jid, password)
5151

52+
self.name = name
53+
self.email = email
54+
5255
# The session_start event will be triggered when
5356
# the bot establishes its connection with the server
5457
# and the XML streams are ready for use. We want to
@@ -102,11 +105,18 @@ def register(self, iq):
102105
To get the list of basic registration fields, you can use:
103106
iq['register']['fields']
104107
"""
108+
105109
resp = self.Iq()
106110
resp['type'] = 'set'
107111
resp['register']['username'] = self.boundjid.user
108112
resp['register']['password'] = self.password
109113

114+
if self.name:
115+
resp['register']['name'] = self.name
116+
117+
if self.email:
118+
resp['register']['email'] = self.email
119+
110120
# TODO: Raise exception if fails
111121
try:
112122
resp.send(now=True)
@@ -120,11 +130,11 @@ def register(self, iq):
120130
self.disconnect()
121131

122132

123-
def register_account(jid, password):
133+
def register_account(jid, password, name=None, email=None):
124134
# Setup the RegisterBot and register plugins. Note that while plugins may
125135
# have interdependencies, the order in which you register them does
126136
# not matter.
127-
xmpp = RegisterBot(jid, password)
137+
xmpp = RegisterBot(jid, password, name, email)
128138
xmpp.register_plugin('xep_0030') # Service Discovery
129139
xmpp.register_plugin('xep_0004') # Data forms
130140
xmpp.register_plugin('xep_0066') # Out-of-band Data

conversejs/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import uuid
3+
24
from django.conf import settings
35
from .models import XMPPAccount
46
from .boshclient import BOSHClient
@@ -44,10 +46,10 @@ def get_conversejs_context(context, xmpp_login=False):
4446
return context
4547

4648
xmpp_jid = request.user.username + u'@' + jid_domain
47-
xmpp_password = '123'
48-
# ... password = get_password()
49+
xmpp_password = uuid.uuid4().hex # get a random uuid as password
4950

50-
registered = register_account(xmpp_jid, xmpp_password)
51+
registered = register_account(xmpp_jid, xmpp_password,
52+
request.user.get_full_name(), request.user.email)
5153

5254
if not registered:
5355
return context

0 commit comments

Comments
 (0)