changeset 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 15f43b54d697
children b262ae6d53af
files src/plugins/plugin_misc_account.py src/plugins/plugin_misc_smtp.py
diffstat 2 files changed, 27 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_account.py	Wed May 07 16:02:23 2014 +0200
+++ b/src/plugins/plugin_misc_account.py	Mon May 12 17:51:38 2014 +0200
@@ -102,7 +102,7 @@
         @param command: the command to execute: "adduser", "passwd" or "deluser"
         @param password: the user new password (leave to None for "deluser" command)
         @param profile: the user profile
-        @return a Deferred instance
+        @return: a Deferred instance
         """
         d = defer.Deferred()
         prosody_reg = ProsodyRegisterProtocol(password, d)
@@ -161,12 +161,19 @@
         if profile.lower() in self.getConfig('reserved_list'):
             return defer.fail(Failure(exceptions.ConflictError))
 
-        d = self.host.memory.asyncCreateProfile(profile)
+        d = self.host.memory.asyncCreateProfile(profile, password)
         d.addCallback(self._profileRegistered, email, password, profile)
         return d
 
     def _profileRegistered(self, result, email, password, profile):
+        """Create the profile and the XMPP account.
 
+        @param result: result of asyncCreateProfile
+        @param email: user email
+        @param password: chosen xmpp password
+        @param profile: %(doc_profile)s
+        @return: a deferred None value when all the processing is done
+        """
         #FIXME: values must be in a config file instead of hardcoded
         self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')),
                                   "Connection", profile_key=profile)
@@ -176,8 +183,8 @@
                                   "Connection", profile_key=profile)
         #and the account
 
-        #XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
-        #     and just change the password if the account already exists
+        # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
+        #      and just change the password if the account already exists
         d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
         d.addCallback(self._sendEmails, profile, email, password)
         d.addCallback(lambda ignore: None)
@@ -244,7 +251,7 @@
         """Get the main dialog to manage your account
         @param menu_data
         @param profile: %(doc_profile)s
-        @return XML of the dialog
+        @return: XML of the dialog
         """
         form_ui = xml_tools.XMLUI("form", "tabs", title=D_("Manage your XMPP account"), submit_id=self.__account_cb_id)
         tab_container = form_ui.current_container
@@ -273,25 +280,26 @@
         form_ui.addBool("delete_checkbox", "false")
         return form_ui.toXml()
 
+    @defer.inlineCallbacks
     def _accountDialogCb(self, data, profile):
         """Called when the user submits the main account dialog
         @param data
         @param profile
         """
-        password = self.host.memory.getParamA("Password", "Connection", profile_key=profile)
+        password = yield self.host.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
 
         def error_ui():
             error_ui = xml_tools.XMLUI("popup", title=D_("Error"))
             error_ui.addText(D_("Passwords don't match!"))
-            return defer.succeed({'xmlui': error_ui.toXml()})
+            return {'xmlui': error_ui.toXml()}
 
         # check for account deletion
         delete_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_passwd']
         delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox']
         if delete_checkbox == 'true':
             if password == delete_passwd:
-                return self.__deleteAccount(profile)
-            return error_ui()
+                defer.returnValue(self.__deleteAccount(profile))
+            defer.returnValue(error_ui())
 
         # check for blog posts deletion
         if 'GROUPBLOG' in self.host.plugins:
@@ -302,8 +310,8 @@
             comments = delete_comments_checkbox == 'true'
             if posts or comments:
                 if password == delete_posts_passwd:
-                    return self.__deleteBlogPosts(posts, comments, profile)
-                return error_ui()
+                    defer.returnValue(self.__deleteBlogPosts(posts, comments, profile))
+                defer.returnValue(error_ui())
 
         # check for password modification
         current_passwd = data[xml_tools.SAT_FORM_PREFIX + 'current_passwd']
@@ -311,10 +319,11 @@
         new_passwd2 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd2']
         if new_passwd1 or new_passwd2:
             if password == current_passwd and new_passwd1 == new_passwd2:
-                return self.__changePassword(new_passwd1, profile=profile)
-            return error_ui()
+                data = yield self.__changePassword(new_passwd1, profile=profile)
+                defer.returnValue(data)
+            defer.returnValue(error_ui())
 
-        return defer.succeed({})
+        defer.returnValue({})
 
     def __changePassword(self, password, profile):
         """Actually change the user XMPP account and SàT profile password
--- a/src/plugins/plugin_misc_smtp.py	Wed May 07 16:02:23 2014 +0200
+++ b/src/plugins/plugin_misc_smtp.py	Mon May 12 17:51:38 2014 +0200
@@ -180,10 +180,10 @@
         profiles = self.host.memory.getProfilesList()
         if not credentials.username in profiles:
             return defer.fail(cred_error.UnauthorizedLogin())
-        password = self.host.memory.getParamA("Password", "Connection", profile_key=credentials.username)
-        return defer.maybeDeferred(credentials.checkPassword,
-                                   password).addCallback(self._cbPasswordMatch,
-                                                         credentials.username)
+        d = self.host.memory.asyncGetParamA("Password", "Connection", profile_key=credentials.username)
+        d.addCallback(credentials.checkPassword)
+        d.addCallback(self._cbPasswordMatch, credentials.username)
+        return d
 
 
 class SmtpServerFactory(smtp.SMTPFactory):