VirtualMailManager/cli/handler.py
branchv0.6.x
changeset 337 150ddcc8b315
parent 320 011066435e6f
child 339 abff2de9eed0
equal deleted inserted replaced
336:d24c2ea39710 337:150ddcc8b315
    12 
    12 
    13 from VirtualMailManager.errors import VMMError
    13 from VirtualMailManager.errors import VMMError
    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 INVALID_SECTION
    17 from VirtualMailManager.constants import ACCOUNT_EXISTS, INVALID_SECTION
    18 
    18 
    19 _ = lambda msg: msg
    19 _ = lambda msg: msg
    20 
    20 
    21 
    21 
    22 class CliHandler(Handler):
    22 class CliHandler(Handler):
    66         else:
    66         else:
    67             raise VMMError(_(u'Invalid section: ā€œ%sā€') % section,
    67             raise VMMError(_(u'Invalid section: ā€œ%sā€') % section,
    68                            INVALID_SECTION)
    68                            INVALID_SECTION)
    69 
    69 
    70     def user_add(self, emailaddress, password=None):
    70     def user_add(self, emailaddress, password=None):
    71         """Prefix the parent user_add() with the interactive password
    71         """Override the parent user_add() - add the interactive password
    72         dialog."""
    72         dialog."""
       
    73         acc = self._get_account(emailaddress)
       
    74         if acc:
       
    75             raise VMMError(_(u"The account '%s' already exists.") %
       
    76                            acc.address, ACCOUNT_EXISTS)
    73         if password is None:
    77         if password is None:
    74             password = read_pass()
    78             password = read_pass()
    75         super(CliHandler, self).user_add(emailaddress, password)
    79         acc.set_password(password)
       
    80         acc.save()
       
    81         self._make_account_dirs(acc)
    76 
    82 
    77     def user_password(self, emailaddress, password=None):
    83     def user_password(self, emailaddress, password=None):
    78         """Prefix the parent user_password() with the interactive password
    84         """Prefix the parent user_password() with the interactive password
    79         dialog."""
    85         dialog."""
    80         if password is None:
    86         if password is None: