comparison src/plugins/plugin_misc_account.py @ 1080:f25ec9fd7cc4

plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
author souliane <souliane@mailoo.org>
date Thu, 19 Jun 2014 19:20:52 +0200
parents 85c110c0be86
children b29452cab50b
comparison
equal deleted inserted replaced
1079:c0ef97002ef4 1080:f25ec9fd7cc4
172 d = self.host.memory.asyncCreateProfile(profile, password) 172 d = self.host.memory.asyncCreateProfile(profile, password)
173 d.addCallback(self._profileRegistered, email, password, profile) 173 d.addCallback(self._profileRegistered, email, password, profile)
174 return d 174 return d
175 175
176 def _profileRegistered(self, result, email, password, profile): 176 def _profileRegistered(self, result, email, password, profile):
177 """Create the profile and the XMPP account. 177 """Create the XMPP account and send the confirmation email.
178 178
179 @param result: result of asyncCreateProfile 179 @param result: result of asyncCreateProfile
180 @param email: user email 180 @param email: user email
181 @param password: chosen xmpp password 181 @param password: chosen xmpp password
182 @param profile: %(doc_profile)s 182 @param profile: %(doc_profile)s
183 @return: a deferred None value when all the processing is done 183 @return: a deferred None value when all the processing is done
184 """ 184 """
185 #FIXME: values must be in a config file instead of hardcoded
186 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
187 "Connection", profile_key=profile)
188 self.host.memory.setParam("Server", self.getConfig('new_account_server'),
189 "Connection", profile_key=profile)
190 self.host.memory.setParam("Password", password,
191 "Connection", profile_key=profile)
192 #and the account
193
194 # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict 185 # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
195 # and just change the password if the account already exists 186 # and just change the password if the account already exists
196 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile) 187 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
197 d.addCallback(self._sendEmails, profile, email, password) 188 d.addCallback(self._sendEmails, profile, email, password)
198 d.addCallback(lambda ignore: None) 189 d.addCallback(lambda ignore: None)
190
191 def setParams(dummy):
192 #FIXME: values must be in a config file instead of hardcoded
193 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
194 "Connection", profile_key=profile)
195 self.host.memory.setParam("Server", self.getConfig('new_account_server'),
196 "Connection", profile_key=profile)
197 self.host.memory.setParam("Password", password,
198 "Connection", profile_key=profile)
199
200 def removeProfile(failure):
201 self.host.memory.asyncDeleteProfile(profile)
202 return failure
203
204 d.addCallback(setParams)
205 d.addErrback(removeProfile)
199 return d 206 return d
200 207
201 def _sendEmails(self, result, login, email, password): 208 def _sendEmails(self, result, login, email, password):
202 #time to send the email 209 #time to send the email
203 210