VMM/handler: Added method Handler.user_pwhash. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Sun, 23 Feb 2014 18:05:53 +0000
branchv0.7.x
changeset 736 66a5f9a405da
parent 735 ddcad86f7386
child 737 81f4bfc34ed8
VMM/handler: Added method Handler.user_pwhash.
VirtualMailManager/handler.py
--- a/VirtualMailManager/handler.py	Sun Feb 23 18:00:35 2014 +0000
+++ b/VirtualMailManager/handler.py	Sun Feb 23 18:05:53 2014 +0000
@@ -40,6 +40,7 @@
 from VirtualMailManager.errors import \
      DomainError, NotRootError, PermissionError, VMMError
 from VirtualMailManager.mailbox import new as new_mailbox
+from VirtualMailManager.password import extract_scheme, verify_scheme
 from VirtualMailManager.quotalimit import QuotaLimit
 from VirtualMailManager.relocated import Relocated
 from VirtualMailManager.serviceset import ServiceSet, SERVICES
@@ -765,6 +766,20 @@
                            acc.address, NO_SUCH_ACCOUNT)
         acc.update_password(password, scheme)
 
+    def user_pwhash(self, emailaddress, pwhash):
+        """Wrapper for Account.modify('pwhash', ...)"""
+        scheme = extract_scheme(pwhash)
+        if not scheme:
+            raise VMMError(_('Missing {SCHEME} prefix from password hash.'),
+                           INVALID_ARGUMENT)
+        else:
+            scheme, encoding = verify_scheme(scheme)  # or die …
+        acc = self._get_account(emailaddress)
+        if not acc:
+            raise VMMError(_("The account '%s' does not exist.") %
+                           acc.address, NO_SUCH_ACCOUNT)
+        acc.modify('pwhash', pwhash)
+
     def user_name(self, emailaddress, name):
         """Wrapper for Account.modify('name', ...)."""
         acc = self._get_account(emailaddress)