Exemplo n.º 1
0
    def __getNewAcctName(self):
        """
        Gets the requested account name of the new account.
        If logout or cancel is given as input this funciton will return and
        the status of this object will indicate what caused the return.

        Ensures that the given account name is in valid format as described by
        the requirements.
        """
        validName = False
        name = None
        while not validName:
            inName = ri('Input the account name for the new account: ',
                        toLower=False)
            if inName == 'logout' or inName == 'off':
                self.status = Status.LOGOUT
                validName = True
            elif inName == 'cancel':
                self.status = Status.CANCEL
                validName = True
            elif len(inName) < 3 or len(inName) > 30:
                print('Account names must be between 3 and 30 characters. '
                      'Please choose a different account name.')
            elif not inName.replace(' ', '').isalnum():
                print('Account names must only contain alphanumeric characters'
                      ' and spaces. Please choose a different account name.')
            else:
                validName = True
                name = inName
        return name
Exemplo n.º 2
0
    def __getOldAcctName(self):
        """
        Gets the account name of the account to delete.
        If logout or cancel is given as input this funciton will return and
        the status of this object will indicate what caused the return.

        Ensures that the account name given is in a valid format to decrease
        the chance of a typo causing the deletion to fail when the transaction
        is being authenticated by the back end.
        """
        validName = False
        name = None
        while not validName:
            inName = ri('Input the account name of account to delete: ',
                        toLower=False)
            if inName == 'logout' or inName == 'off':
                self.status = Status.LOGOUT
                validName = True
            elif inName == 'cancel':
                self.status = Status.CANCEL
                validName = True
            elif len(inName) < 3 or len(inName) > 30:
                print('Account names must be between 3 and 30 characters. '
                      'Please enter a valid account name.')
            elif not inName.replace(' ', '').isalnum():
                print('Account names must only contain alphanumeric characters'
                      ' and spaces. Please enter a valid account name.')
            else:
                validName = True
                name = inName
        return name
Exemplo n.º 3
0
    def __getOldAcctNum(self):
        """
        Gets the account number of the account to delete.
        If logout or cancel is given as input this funciton will return and
        the status of this object will indicate what caused the return.

        Ensures that the account trying to be deleted is actually a current
        valid account.
        """
        validNum = False
        num = None
        while not validNum:
            inNum = ri('Input the account number of account to delete: ')
            if inNum == 'logout' or inNum == 'off':
                self.status = Status.LOGOUT
                validNum = True
            elif inNum == 'cancel':
                self.status = Status.CANCEL
                validNum = True
            elif inNum not in self.validAcctsList.keys():
                print('{} is not a valid account. Please enter a valid '
                      'account'.format(inNum))
            else:
                validNum = True
                num = inNum
        return num
Exemplo n.º 4
0
    def __getNewAcctNum(self):
        """
        Gets the requested account number of the new account.
        If logout or cancel is given as input this funciton will return and
        the status of this object will indicate what caused the return.

        Ensures that the given account number is in valid format as described
        by the requirements.
        """
        validNum = False
        num = None
        while not validNum:
            inNum = ri('Input the account number for the new account: ')
            if inNum == 'logout' or inNum == 'off':
                self.status = Status.LOGOUT
                validNum = True
            elif inNum == 'cancel':
                self.status = Status.CANCEL
                validNum = True
            elif not inNum.isdigit():
                print('Account numbers must be comprised of only digits. '
                      'Please choose a different account number.')
            elif len(inNum) != 7:
                print('Account numbers must be exactly 7 digits in length. '
                      'Please choose a different account number.')
            elif inNum == '0000000':
                print('0000000 is a reserved account number. Please choose a '
                      'different account number.')
            elif inNum[0] == '0':
                print('Account numbers must not begin with a "0". Please '
                      'choose a different account number.')
            elif inNum in self.validAcctsList.keys():
                print('{} is already in use. Please choose a different account'
                      ' number.'.format(inNum))
            elif inNum in self.createdAccts:
                print('{} is already in use. Please choose a different account'
                      ' number.'.format(inNum))
            else:
                validNum = True
                num = inNum
        return num
Exemplo n.º 5
0
 def getNumber(self, fromAcct):
     """
     Returns a given number in cents only when entered in the correct format
     """
     validNumber = False
     # need a way to determine the transfer total for every account
     while not validNumber:
         numberString = ri('Enter a number to deposit in cents: ')
         if numberString.isdigit():
             number = int(numberString)
         else:
             number = 0
         if numberString == "cancel":
             self.status = Status.CANCEL
             validNumber = True
         elif numberString == "off" or numberString == "logout":
             self.status = Status.LOGOUT
             validNumber = True
         elif not numberString.isdigit():
             print("Please only enter digits")
         elif number > 1000000 and self.mode == Modes.ATM:
             print("Maximum transfer of "
                   u'\xa2'
                   "1000000 per transaction "
                   "in ATM mode")
         elif number > 99999999 and self.mode == Modes.TELLER:
             print("Maximum transfer of "
                   u'\xa2'
                   "99999999 per transaction "
                   "in Teller mode")
         elif number < 1:
             print("Must deposit at least 1 cent")
         elif (self.validAcctsList[fromAcct]['transfer'] +
               number) > 500000 and self.mode == Modes.ATM:
             print("maximum transfer of " u'\xa2' "1000000 a day")
         else:
             validNumber = True
     return number
Exemplo n.º 6
0
    def getMode(self):
        """
        Function to ask get the requested banking system mode from the user.

        Logout and cancel may also be given as input rather than completing
        the login.
        Inputs of "?" and "help" can be used to prompt the user of possible
        valid options.
        """
        validMode = False
        retMode = Modes.NA
        while not validMode:
            mode = ri('Enter the desired mode [agent or machine]: ')
            if mode == 'agent':
                validMode = True
                retMode = Modes.TELLER
                self.status = Status.OK
            elif mode == 'machine':
                validMode = True
                retMode = Modes.ATM
                self.status = Status.OK
            elif mode == 'cancel':
                validMode = True
                retMode = Modes.NA
                self.status = Status.CANCEL
            elif mode == 'logout':
                validMode = True
                retMode = Modes.NA
                self.status = Status.LOGOUT
            else:
                string = 'Please enter either agent or machine if you wish to'\
                         ' continue\nIf you do not wish to continue, please '\
                         'enter either cancel or logout'
                if mode != '?' and mode != 'help':
                    string = 'Unrecognized mode "{}". {}'.format(mode, string)
                print(string)
        return retMode
Exemplo n.º 7
0
def main():
    """
    The main loop of the Quinterac banking system. Creates a session object
    and then passes commands to it from the user input.
    Commands at this level will only be the transaction commands, ie, login,
    logout, withdraw, etc. Not the sub-commands such as the amount to
    withdraw/transfer/deposit or the login mode of agent or machine.
    """
    validAccts, summaryFile = parseArgs()
    if not areFilesValid(validAccts, summaryFile):
        return RetCode.ERROR
    session = Session(validAccts, summaryFile)
    prompt = 'Quinterac: '
    while session.state != State.END:
        if session.mode == Modes.TELLER:
            prompt = 'Quinterac [Teller]: '
        elif session.mode == Modes.ATM:
            prompt = 'Quinterac [ATM]: '
        else:
            prompt = 'Quinterac: '
        command = ri(prompt=prompt)
        session.handleCommand(command)

    return RetCode.OK
Exemplo n.º 8
0
    def getAcct(self, text):
        """
        Accepts input and only returns given a valid account numberm or None.

        @param text The prompt to be used for the input function.
        """
        validNum = False
        num = None
        while not validNum:
            inNum = ri(text)
            if inNum == 'logout' or inNum == 'off':
                self.status = Status.LOGOUT
                validNum = True
            elif inNum == 'cancel':
                self.status = Status.CANCEL
                validNum = True
            elif inNum not in self.validAcctsList.keys():
                print('{} is not a valid account. Please enter a valid '
                      'account'.format(inNum))
            else:
                validNum = True
                self.acctNumber = inNum
                num = inNum
        return num