# HG changeset patch # User Pascal Volk # Date 1281402141 0 # Node ID 971577b89d26b348a1d8121fed3dbf207c0a9f87 # Parent 44283818f8dbe20b33894d341362725a4859040a VMM/cli/handler: Added support for random passwords in user_add(). diff -r 44283818f8db -r 971577b89d26 VirtualMailManager/cli/handler.py --- a/VirtualMailManager/cli/handler.py Mon Aug 09 19:39:55 2010 +0000 +++ b/VirtualMailManager/cli/handler.py Tue Aug 10 01:02:21 2010 +0000 @@ -16,6 +16,7 @@ from VirtualMailManager.cli.config import CliConfig as Cfg from VirtualMailManager.constants import ACCOUNT_EXISTS, INVALID_SECTION, \ NO_SUCH_ACCOUNT +from VirtualMailManager.password import randompw _ = lambda msg: msg @@ -67,16 +68,21 @@ def user_add(self, emailaddress, password=None): """Override the parent user_add() - add the interactive password - dialog.""" + dialog. + + Returns the generated password, if account.random_password == True. + """ acc = self._get_account(emailaddress) if acc: raise VMMError(_(u"The account '%s' already exists.") % acc.address, ACCOUNT_EXISTS) + rand_pass = self._cfg.dget('account.random_password') if password is None: - password = read_pass() + password = (read_pass, randompw)[rand_pass]() acc.set_password(password) acc.save() self._make_account_dirs(acc) + return (None, password)[rand_pass] def user_password(self, emailaddress, password=None): """Override the parent user_password() - add the interactive diff -r 44283818f8db -r 971577b89d26 VirtualMailManager/cli/subcommands.py --- a/VirtualMailManager/cli/subcommands.py Mon Aug 09 19:39:55 2010 +0000 +++ b/VirtualMailManager/cli/subcommands.py Tue Aug 10 01:02:21 2010 +0000 @@ -380,7 +380,9 @@ password = None else: password = ctx.args[3] - ctx.hdlr.user_add(ctx.args[2].lower(), password) + gen_pass = ctx.hdlr.user_add(ctx.args[2].lower(), password) + if gen_pass: + w_std(_(u"Generated password: %s") % gen_pass) def user_delete(ctx): diff -r 44283818f8db -r 971577b89d26 man/de/man1/vmm.1.rst --- a/man/de/man1/vmm.1.rst Mon Aug 09 19:39:55 2010 +0000 +++ b/man/de/man1/vmm.1.rst Tue Aug 10 01:02:21 2010 +0000 @@ -7,7 +7,7 @@ ----------------------------------------------------------------------------- :Author: Pascal Volk -:Date: 2010-08-01 +:Date: |today| :Version: vmm-0.6.0 :Manual group: vmm Manual :Manual section: 1 @@ -288,7 +288,10 @@ angelegt. Wurde kein *Passwort* angegeben wird **vmm** dieses im interaktiven Modus - erfragen. + erfragen. Falls kein *Passwort* angegeben wurde und + |account.random_password|_ den Wert **true** hat, wird **vmm** ein + zufälliges Passwort generieren und auf stdout ausgeben, nachdem das Konto + angelegt wurde. Beispiele:: diff -r 44283818f8db -r 971577b89d26 man/man1/vmm.1.rst --- a/man/man1/vmm.1.rst Mon Aug 09 19:39:55 2010 +0000 +++ b/man/man1/vmm.1.rst Tue Aug 10 01:02:21 2010 +0000 @@ -7,7 +7,7 @@ ---------------------------------------------------------- :Author: Pascal Volk -:Date: 2010-08-01 +:Date: |today| :Version: vmm-0.6.0 :Manual group: vmm Manual :Manual section: 1 @@ -270,7 +270,9 @@ Use this subcommand to create a new email account for the given *address*. If the *password* is not provided, **vmm** will prompt for it - interactively. + interactively. When no *password* is provided and |account.random_password|_ + is set to **true**, **vmm** will generate a random password and print it to + stdout after the account has been created. Examples:: diff -r 44283818f8db -r 971577b89d26 man/substitute_links_1.rst --- a/man/substitute_links_1.rst Mon Aug 09 19:39:55 2010 +0000 +++ b/man/substitute_links_1.rst Tue Aug 10 01:02:21 2010 +0000 @@ -2,6 +2,8 @@ .. |account.disk_usage| replace:: `account.disk_usage` .. _account.disk_usage: vmm.cfg.5#account-disk-usage +.. |account.random_password| replace:: `account.random_password` +.. _account.random_password: vmm.cfg.5#account-random-password .. |domain.force_deletion| replace:: `domain.force_deletion` .. _domain.force_deletion: vmm.cfg.5#domain-force-deletion