comparison src/plugins/plugin_misc_account.py @ 1031:e90125d07072

plugins misc_account, misc_smtp: update the plugins that deal with passwords
author souliane <souliane@mailoo.org>
date Mon, 12 May 2014 17:51:38 +0200
parents 301b342c697a
children 76ad41b708e1
comparison
equal deleted inserted replaced
1030:15f43b54d697 1031:e90125d07072
100 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command. 100 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command.
101 @param plugin: instance of MiscAccount 101 @param plugin: instance of MiscAccount
102 @param command: the command to execute: "adduser", "passwd" or "deluser" 102 @param command: the command to execute: "adduser", "passwd" or "deluser"
103 @param password: the user new password (leave to None for "deluser" command) 103 @param password: the user new password (leave to None for "deluser" command)
104 @param profile: the user profile 104 @param profile: the user profile
105 @return a Deferred instance 105 @return: a Deferred instance
106 """ 106 """
107 d = defer.Deferred() 107 d = defer.Deferred()
108 prosody_reg = ProsodyRegisterProtocol(password, d) 108 prosody_reg = ProsodyRegisterProtocol(password, d)
109 prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl')) 109 prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl'))
110 # TODO delete account which are not on the same host 110 # TODO delete account which are not on the same host
159 raise exceptions.DataError 159 raise exceptions.DataError
160 160
161 if profile.lower() in self.getConfig('reserved_list'): 161 if profile.lower() in self.getConfig('reserved_list'):
162 return defer.fail(Failure(exceptions.ConflictError)) 162 return defer.fail(Failure(exceptions.ConflictError))
163 163
164 d = self.host.memory.asyncCreateProfile(profile) 164 d = self.host.memory.asyncCreateProfile(profile, password)
165 d.addCallback(self._profileRegistered, email, password, profile) 165 d.addCallback(self._profileRegistered, email, password, profile)
166 return d 166 return d
167 167
168 def _profileRegistered(self, result, email, password, profile): 168 def _profileRegistered(self, result, email, password, profile):
169 169 """Create the profile and the XMPP account.
170
171 @param result: result of asyncCreateProfile
172 @param email: user email
173 @param password: chosen xmpp password
174 @param profile: %(doc_profile)s
175 @return: a deferred None value when all the processing is done
176 """
170 #FIXME: values must be in a config file instead of hardcoded 177 #FIXME: values must be in a config file instead of hardcoded
171 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')), 178 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
172 "Connection", profile_key=profile) 179 "Connection", profile_key=profile)
173 self.host.memory.setParam("Server", self.getConfig('new_account_server'), 180 self.host.memory.setParam("Server", self.getConfig('new_account_server'),
174 "Connection", profile_key=profile) 181 "Connection", profile_key=profile)
175 self.host.memory.setParam("Password", password, 182 self.host.memory.setParam("Password", password,
176 "Connection", profile_key=profile) 183 "Connection", profile_key=profile)
177 #and the account 184 #and the account
178 185
179 #XXX: we use "prosodyctl adduser" because "register" doesn't check conflict 186 # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
180 # and just change the password if the account already exists 187 # and just change the password if the account already exists
181 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile) 188 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
182 d.addCallback(self._sendEmails, profile, email, password) 189 d.addCallback(self._sendEmails, profile, email, password)
183 d.addCallback(lambda ignore: None) 190 d.addCallback(lambda ignore: None)
184 return d 191 return d
185 192
242 249
243 def _getAccountDialogUI(self, profile): 250 def _getAccountDialogUI(self, profile):
244 """Get the main dialog to manage your account 251 """Get the main dialog to manage your account
245 @param menu_data 252 @param menu_data
246 @param profile: %(doc_profile)s 253 @param profile: %(doc_profile)s
247 @return XML of the dialog 254 @return: XML of the dialog
248 """ 255 """
249 form_ui = xml_tools.XMLUI("form", "tabs", title=D_("Manage your XMPP account"), submit_id=self.__account_cb_id) 256 form_ui = xml_tools.XMLUI("form", "tabs", title=D_("Manage your XMPP account"), submit_id=self.__account_cb_id)
250 tab_container = form_ui.current_container 257 tab_container = form_ui.current_container
251 258
252 tab_container.addTab("update", D_("Change your password"), container=xml_tools.PairsContainer) 259 tab_container.addTab("update", D_("Change your password"), container=xml_tools.PairsContainer)
271 form_ui.addPassword("delete_passwd", value="") 278 form_ui.addPassword("delete_passwd", value="")
272 form_ui.addLabel(D_("Delete your account")) 279 form_ui.addLabel(D_("Delete your account"))
273 form_ui.addBool("delete_checkbox", "false") 280 form_ui.addBool("delete_checkbox", "false")
274 return form_ui.toXml() 281 return form_ui.toXml()
275 282
283 @defer.inlineCallbacks
276 def _accountDialogCb(self, data, profile): 284 def _accountDialogCb(self, data, profile):
277 """Called when the user submits the main account dialog 285 """Called when the user submits the main account dialog
278 @param data 286 @param data
279 @param profile 287 @param profile
280 """ 288 """
281 password = self.host.memory.getParamA("Password", "Connection", profile_key=profile) 289 password = yield self.host.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
282 290
283 def error_ui(): 291 def error_ui():
284 error_ui = xml_tools.XMLUI("popup", title=D_("Error")) 292 error_ui = xml_tools.XMLUI("popup", title=D_("Error"))
285 error_ui.addText(D_("Passwords don't match!")) 293 error_ui.addText(D_("Passwords don't match!"))
286 return defer.succeed({'xmlui': error_ui.toXml()}) 294 return {'xmlui': error_ui.toXml()}
287 295
288 # check for account deletion 296 # check for account deletion
289 delete_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_passwd'] 297 delete_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_passwd']
290 delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox'] 298 delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox']
291 if delete_checkbox == 'true': 299 if delete_checkbox == 'true':
292 if password == delete_passwd: 300 if password == delete_passwd:
293 return self.__deleteAccount(profile) 301 defer.returnValue(self.__deleteAccount(profile))
294 return error_ui() 302 defer.returnValue(error_ui())
295 303
296 # check for blog posts deletion 304 # check for blog posts deletion
297 if 'GROUPBLOG' in self.host.plugins: 305 if 'GROUPBLOG' in self.host.plugins:
298 delete_posts_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_passwd'] 306 delete_posts_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_passwd']
299 delete_posts_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_checkbox'] 307 delete_posts_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_checkbox']
300 delete_comments_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_comments_checkbox'] 308 delete_comments_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_comments_checkbox']
301 posts = delete_posts_checkbox == 'true' 309 posts = delete_posts_checkbox == 'true'
302 comments = delete_comments_checkbox == 'true' 310 comments = delete_comments_checkbox == 'true'
303 if posts or comments: 311 if posts or comments:
304 if password == delete_posts_passwd: 312 if password == delete_posts_passwd:
305 return self.__deleteBlogPosts(posts, comments, profile) 313 defer.returnValue(self.__deleteBlogPosts(posts, comments, profile))
306 return error_ui() 314 defer.returnValue(error_ui())
307 315
308 # check for password modification 316 # check for password modification
309 current_passwd = data[xml_tools.SAT_FORM_PREFIX + 'current_passwd'] 317 current_passwd = data[xml_tools.SAT_FORM_PREFIX + 'current_passwd']
310 new_passwd1 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd1'] 318 new_passwd1 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd1']
311 new_passwd2 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd2'] 319 new_passwd2 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd2']
312 if new_passwd1 or new_passwd2: 320 if new_passwd1 or new_passwd2:
313 if password == current_passwd and new_passwd1 == new_passwd2: 321 if password == current_passwd and new_passwd1 == new_passwd2:
314 return self.__changePassword(new_passwd1, profile=profile) 322 data = yield self.__changePassword(new_passwd1, profile=profile)
315 return error_ui() 323 defer.returnValue(data)
316 324 defer.returnValue(error_ui())
317 return defer.succeed({}) 325
326 defer.returnValue({})
318 327
319 def __changePassword(self, password, profile): 328 def __changePassword(self, password, profile):
320 """Actually change the user XMPP account and SàT profile password 329 """Actually change the user XMPP account and SàT profile password
321 @param password: new password 330 @param password: new password
322 @profile 331 @profile