Esempio n. 1
0
    def getState(self, current=None):
        print('Account state requested by: ' + current.ctx['pesel'])

        try:
            account = checkSignIn(int(current.ctx['pesel']),
                                  current.ctx['password'])
            if not account:
                raise Bank.AccountException(
                    'Please provide correct login info')
            else:
                return Bank.Account(account.pesel, account.name,
                                    account.surname, account.income,
                                    account.type, account.password)
        except ValueError:
            raise Bank.AccountException('Please provide correct arguments')
Esempio n. 2
0
def getFromEnum(currency):
    if currency == 'PLN':
        return Bank.Currency.PLN
    elif currency == 'USD':
        return Bank.Currency.USD
    elif currency == 'EURO':
        return Bank.Currency.EURO
    else:
        raise Bank.AccountException('Provide a correct currency')
Esempio n. 3
0
    def signUp(self, pesel, name, surname, income, current=None):
        print('Registration requested by: ' + str(pesel))
        if any([pesel == account.pesel for account in accounts]):
            raise Bank.AccountException('Already signed up!')

        account = Bank.Account(
            pesel, name, surname, income, Bank.AccountType.PREMIUM
            if income >= premiumThreshold else Bank.AccountType.STANDARD,
            getNewPassword())
        accounts.append(account)

        return account.password
Esempio n. 4
0
    def requestLoan(self, currency, loanAmount, months, current=None):
        print('Login requested by: ' + current.ctx['pesel'])

        account = checkSignIn(int(current.ctx['pesel']),
                              current.ctx['password'])

        if not account:
            raise Bank.AccountException('Please provide correct login info')
        else:
            if account.type == Bank.AccountType.STANDARD:
                raise Bank.AccountException(
                    'Requesting a loan requires a PREMIUM account!')
            else:
                try:
                    foreignCurrencyValue = next(
                        currencyIter['value'] for currencyIter in currencyTable
                        if currencyIter['type'] == currency.name)
                    return Bank.LoanRates(
                        loanAmount * loanInterest,
                        loanAmount * loanInterest * foreignCurrencyValue)
                except StopIteration:
                    raise Bank.AccountException(
                        'Please provide a valid currency!')
Esempio n. 5
0
    def createAccount(self, firstName, lastName, pin, income, current=None):
        if any([pin == acc.getPin() for acc in accountTable]):
            raise Bank.AccountException(
                'Account with Personal Identity Number like that already exists!'
            )

        if (income >= 5000):
            newType = Bank.AccountType.PREMIUM
        else:
            newType = Bank.AccountType.STANDARD
        newPassword = "******" + str(random.randrange(1, 100))
        newAccount = Account(
            {
                'firstName': firstName,
                'lastName': lastName,
                'pin': pin,
                'income': income
            }, newPassword, newType, 0)
        accountTable.append(newAccount)

        return Bank.RegistrationInfo(newPassword, newType)