comparison src/plugins/plugin_misc_invitations.py @ 2256:61e836cc9512

plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
author Goffi <goffi@goffi.org>
date Sun, 21 May 2017 20:08:42 +0200
parents ba613d32ca60
children c05000d00dbb
comparison
equal deleted inserted replaced
2255:ba613d32ca60 2256:61e836cc9512
34 PLUGIN_INFO = { 34 PLUGIN_INFO = {
35 C.PI_NAME: "Invitations", 35 C.PI_NAME: "Invitations",
36 C.PI_IMPORT_NAME: "INVITATIONS", 36 C.PI_IMPORT_NAME: "INVITATIONS",
37 C.PI_TYPE: C.PLUG_TYPE_MISC, 37 C.PI_TYPE: C.PLUG_TYPE_MISC,
38 C.PI_DEPENDENCIES: ['XEP-0077'], 38 C.PI_DEPENDENCIES: ['XEP-0077'],
39 C.PI_RECOMMENDATIONS: ["IDENTITY"],
39 C.PI_MAIN: "InvitationsPlugin", 40 C.PI_MAIN: "InvitationsPlugin",
40 C.PI_HANDLER: "no", 41 C.PI_HANDLER: "no",
41 C.PI_DESCRIPTION: _(u"""invitation of people without XMPP account""") 42 C.PI_DESCRIPTION: _(u"""invitation of people without XMPP account""")
42 } 43 }
43 44
123 same as the invitation one, as jid can be used publicly (leaking the UUID), and invitation UUID give access to account. 124 same as the invitation one, as jid can be used publicly (leaking the UUID), and invitation UUID give access to account.
124 in case of conflict, a suffix number is added to the account until a free one if found (with a failure if SUFFIX_MAX is reached) 125 in case of conflict, a suffix number is added to the account until a free one if found (with a failure if SUFFIX_MAX is reached)
125 password(unicode, None): password to use (will be used for XMPP account and profile) 126 password(unicode, None): password to use (will be used for XMPP account and profile)
126 None to automatically generate one 127 None to automatically generate one
127 name(unicode, None): name of the invitee 128 name(unicode, None): name of the invitee
129 will be set as profile identity if present
128 host_name(unicode, None): name of the host 130 host_name(unicode, None): name of the host
129 email(unicode, None): email to send the invitation to 131 email(unicode, None): email to send the invitation to
130 if None, no invitation email is sent, you can still associate email using extra 132 if None, no invitation email is sent, you can still associate email using extra
131 if email is used, extra can't have "email" key 133 if email is used, extra can't have "email" key
132 language(unicode): language of the invitee (used notabily to translate the invitation) 134 language(unicode): language of the invitee (used notabily to translate the invitation)
168 email = kwargs.pop(u'email', None) 170 email = kwargs.pop(u'email', None)
169 171
170 if email is not None and not 'url_template' in kwargs and not 'message_body' in kwargs: 172 if email is not None and not 'url_template' in kwargs and not 'message_body' in kwargs:
171 raise ValueError(_(u"You need to provide url_template if you use default message body")) 173 raise ValueError(_(u"You need to provide url_template if you use default message body"))
172 174
173
174 ## uuid 175 ## uuid
175 log.info(_(u"creating an invitation")) 176 log.info(_(u"creating an invitation"))
176 id_ = unicode(shortuuid.uuid()) 177 id_ = unicode(shortuuid.uuid())
177 178
178 ## XMPP account creation 179 ## XMPP account creation
218 raise e 219 raise e
219 220
220 log.info(_(u"account {jid_} created").format(jid_=jid_.full())) 221 log.info(_(u"account {jid_} created").format(jid_=jid_.full()))
221 222
222 ## profile creation 223 ## profile creation
224
223 extra[KEY_GUEST_PROFILE] = guest_profile = INVITEE_PROFILE_TPL.format(uuid=id_) 225 extra[KEY_GUEST_PROFILE] = guest_profile = INVITEE_PROFILE_TPL.format(uuid=id_)
224 # profile creation should not fail as we generate unique name ourselves 226 # profile creation should not fail as we generate unique name ourselves
225 yield self.host.memory.createProfile(guest_profile, password) 227 yield self.host.memory.createProfile(guest_profile, password)
226 yield self.host.memory.startSession(password, guest_profile) 228 yield self.host.memory.startSession(password, guest_profile)
227 yield self.host.memory.setParam("JabberID", jid_.full(), "Connection", profile_key=guest_profile) 229 yield self.host.memory.setParam("JabberID", jid_.full(), "Connection", profile_key=guest_profile)
228 yield self.host.memory.setParam("Password", password, "Connection", profile_key=guest_profile) 230 yield self.host.memory.setParam("Password", password, "Connection", profile_key=guest_profile)
231 name = kwargs.pop(u'name', None)
232 if name is not None:
233 extra[u'name'] = name
234 try:
235 id_plugin = self.host.plugins[u'IDENTITY']
236 except KeyError:
237 pass
238 else:
239 yield self.host.connect(guest_profile, password)
240 guest_client = self.host.getClient(guest_profile)
241 yield id_plugin.setIdentity(guest_client, {u'nick': name})
242 yield self.host.disconnect(guest_profile)
229 243
230 ## email 244 ## email
231 language = kwargs.pop(u'language', None) 245 language = kwargs.pop(u'language', None)
232 if language is not None: 246 if language is not None:
233 extra[u'language'] = language 247 extra[u'language'] = language
238 format_args = { 252 format_args = {
239 u'uuid': id_, 253 u'uuid': id_,
240 u'app_name': C.APP_NAME, 254 u'app_name': C.APP_NAME,
241 u'app_url': C.APP_URL} 255 u'app_url': C.APP_URL}
242 256
243 name = kwargs.pop(u'name', None)
244 if name is None: 257 if name is None:
245 format_args[u'name'] = email 258 format_args[u'name'] = email
246 else: 259 else:
247 format_args[u'name'] = extra[u'name'] = name 260 format_args[u'name'] = name
248 261
249 profile = kwargs.pop(u'profile', None) 262 profile = kwargs.pop(u'profile', None)
250 if profile is None: 263 if profile is None:
251 format_args[u'profile'] = u'' 264 format_args[u'profile'] = u''
252 else: 265 else: