VirtualMailManager/cli/handler.py
branchv0.6.x
changeset 361 971577b89d26
parent 346 95d45e4ec1a6
child 366 d6573da35b5f
equal deleted inserted replaced
360:44283818f8db 361:971577b89d26
    14 from VirtualMailManager.handler import Handler
    14 from VirtualMailManager.handler import Handler
    15 from VirtualMailManager.cli import read_pass
    15 from VirtualMailManager.cli import read_pass
    16 from VirtualMailManager.cli.config import CliConfig as Cfg
    16 from VirtualMailManager.cli.config import CliConfig as Cfg
    17 from VirtualMailManager.constants import ACCOUNT_EXISTS, INVALID_SECTION, \
    17 from VirtualMailManager.constants import ACCOUNT_EXISTS, INVALID_SECTION, \
    18      NO_SUCH_ACCOUNT
    18      NO_SUCH_ACCOUNT
       
    19 from VirtualMailManager.password import randompw
    19 
    20 
    20 _ = lambda msg: msg
    21 _ = lambda msg: msg
    21 
    22 
    22 
    23 
    23 class CliHandler(Handler):
    24 class CliHandler(Handler):
    65             raise VMMError(_(u"Invalid section: '%s'") % section,
    66             raise VMMError(_(u"Invalid section: '%s'") % section,
    66                            INVALID_SECTION)
    67                            INVALID_SECTION)
    67 
    68 
    68     def user_add(self, emailaddress, password=None):
    69     def user_add(self, emailaddress, password=None):
    69         """Override the parent user_add() - add the interactive password
    70         """Override the parent user_add() - add the interactive password
    70         dialog."""
    71         dialog.
       
    72 
       
    73         Returns the generated password, if account.random_password == True.
       
    74         """
    71         acc = self._get_account(emailaddress)
    75         acc = self._get_account(emailaddress)
    72         if acc:
    76         if acc:
    73             raise VMMError(_(u"The account '%s' already exists.") %
    77             raise VMMError(_(u"The account '%s' already exists.") %
    74                            acc.address, ACCOUNT_EXISTS)
    78                            acc.address, ACCOUNT_EXISTS)
       
    79         rand_pass = self._cfg.dget('account.random_password')
    75         if password is None:
    80         if password is None:
    76             password = read_pass()
    81             password = (read_pass, randompw)[rand_pass]()
    77         acc.set_password(password)
    82         acc.set_password(password)
    78         acc.save()
    83         acc.save()
    79         self._make_account_dirs(acc)
    84         self._make_account_dirs(acc)
       
    85         return (None, password)[rand_pass]
    80 
    86 
    81     def user_password(self, emailaddress, password=None):
    87     def user_password(self, emailaddress, password=None):
    82         """Override the parent user_password() - add the interactive
    88         """Override the parent user_password() - add the interactive
    83         password dialog."""
    89         password dialog."""
    84         acc = self._get_account(emailaddress)
    90         acc = self._get_account(emailaddress)