Exemplo n.º 1
0
    def __init__(self,
                 status,
                 valids):

        message = "Invalid job status provided. Expected %s, got %s." % (", ".join(valids), status)

        CustomException.__init__(self, message)
Exemplo n.º 2
0
def validateaccno(acc_no):
    if (acc_no.isdigit() == True):
        if (viewdb.validacc(acc_no)):
            return True
        else:
            raise CustomException.invalidaccno()
    else:
        raise CustomException.invalidnumber()
Exemplo n.º 3
0
def validatebalance(amount, acc_no):
    if (amount.isdigit() == True):
        if (viewdb.validbal(amount, acc_no)):
            return True
        else:
            raise CustomException.invalidbal()
    else:
        raise CustomException.invalidnumber()
 def __download_exchange_rate(self) -> Decimal:
     url = f'{NBP_BASE_CURRENCY_URL}{self.curr}?format=json'
     try:
         resp = requests.get(url)
         if resp.status_code == 404:
             raise CustomException("Wrong currency code")
         rate = resp.json()['rates'][0]['mid']
     except KeyError:
         raise CustomException("Problem with external service", 503)
     return Decimal(str(rate))
Exemplo n.º 5
0
def validate_debit_balance(transfer_amount, debit_account):
    if (1000 <= int(transfer_amount) <= 10000):
        deb_bal_verify = viewdb.check_balance_after_transfer(
            transfer_amount, debit_account)
        if deb_bal_verify == 0:
            raise CustomException.LowBalanceException()

        else:
            return 1
    else:
        raise CustomException.invalidtransferammount()
Exemplo n.º 6
0
def get_user(username):
    user = {}
    try:
        user = users.get_users_from_db(username)
        return (jsonify(user), 201)

    except IndexError:
        raise CustomException(status_code=404, message="User Not Found")
        return
    except Exception as e:
        raise CustomException(status_code=500, message="Server Error")
        return
Exemplo n.º 7
0
def validate_custid_password(input_id, input_password):
    if (input_id.isdigit() == True):
        disp_result = viewdb.check_custid_password(input_id, input_password)

        if disp_result == 0:
            raise CustomException.InvalidUserIdPasswordException()

        else:
            return True
        return True
    else:
        raise CustomException.invalidnumber()
Exemplo n.º 8
0
def validate_debit_account(debit_account, cust_id):
    deb_verify = viewdb.check_debit_account(debit_account, cust_id)
    if deb_verify == 0:
        raise CustomException.invalidaccounttype()

    else:
        return True
Exemplo n.º 9
0
def check_mobile(mnumber):
    if (len(mnumber) == 10 and mnumber.isnumeric()):
        db_check = CheckDB.check_mobile(mnumber)
        if (len(db_check) == 0):
            return 1
    else:
        raise CustomException.InvalidMobileException()
Exemplo n.º 10
0
def validate_credit_account(credit_account, debit_account):
    cred_verify = viewdb.check_credit_account(credit_account, debit_account)
    if cred_verify == 0:
        raise CustomException.InvalidCreditAccountException()

    else:
        return 1
Exemplo n.º 11
0
def check_expiry(c_month,c_year):
    now = datetime.datetime.now()
    if(int(c_year)==int(str(now.year)[2:])):
        if(int(c_month)>=now.month):
            return True
    elif(len(c_year)==2 and int(c_year)>int(str(now.year)[2:])):
        if(int(c_month)>0 and int(c_month)<13):
            return True
    raise CustomException.InvalidExpiryException()
Exemplo n.º 12
0
def forget_password():
    try:
        mnumber = input("Enter your Mobile number")
        if (UserValidation.recheck_mobile(mnumber)):
            quesans = CheckDB.get_ques(mnumber)
            print("What is", quesans[0])
            user_ans = input()
            if (UserValidation.recheck_quesans(quesans[1].lower(),
                                               user_ans.lower())):
                print("your password is:", CheckDB.get_user(mnumber))
            else:
                raise CustomException.InvalidAnswerException()
        else:
            raise CustomException.InvalidMobileException()
    except CustomException.InvalidMobileException as e:
        print(e)
    except CustomException.InvalidAnswerException as e:
        print(e)
 def convert(self, amount: str, curr_1: str, curr_2: str) -> float:
     try:
         amount = Decimal(amount)
     except (TypeError, DecimalException):
         raise CustomException('Wrong amount to convert')
     exchange_service_curr_1 = ExchangeRateService(curr=curr_1)
     curr_1_to_pln = exchange_service_curr_1.get_exchange_rate()
     exchange_service_curr_2 = ExchangeRateService(curr=curr_2)
     pln_to_curr_2 = exchange_service_curr_2.get_exchange_rate()
     converted = amount * curr_1_to_pln / pln_to_curr_2
     return round(float(converted), RETURN_PRECISION)
Exemplo n.º 14
0
def check_email(email):
    t_list = email.split('@')
    if (len(t_list) == 2):
        if (t_list[0].count('.') >= 1 and t_list[1].count('.') == 1):
            temp = t_list[0].count('.')
            for i in range(temp):
                x = t_list[0].replace('.', 'p')
            if (x.isalnum()):
                db_check = CheckDB.check_email(email)
                if (len(db_check) == 0):
                    return True
    raise CustomException.InvalidEmailException()
Exemplo n.º 15
0
def put_user(username):
    try:
        usernmae = request.json['usernmae']
        userType = request.json['userType']
        publicInfo = request.json['publicInfo']
        protectedInfo = request.json['protectedInfo']
        privateInfo = request.json['privateInfo']
        users.update_user_in_db(usernmae, userType, publicInfo, protectedInfo,
                                privateInfo)
    except Exception as e:
        raise CustomException(status_code=500, message="Server Error")
        return
    user = {'status': 'success'}
    return (user, 201)
Exemplo n.º 16
0
def convert():
    curr_1 = request.args.get('currency1')
    curr_2 = request.args.get('currency2')
    amount = request.args.get('amount')
    if curr_1 is None or curr_2 is None:
        raise CustomException('Both currency1 and currency2 are needed')
    converter = CurrencyConverterService()
    converted = converter.convert(amount=amount, curr_1=curr_1, curr_2=curr_2)
    payload = {
        'currency1': curr_1,
        'currency2': curr_2,
        'amount': amount,
        'converted': converted,
    }
    return jsonify(payload)
Exemplo n.º 17
0
def check_password(p_word, re_p_word):
    l_flag = u_flag = d_flag = s_flag = 0
    if (len(p_word) > 7 and p_word == re_p_word):
        for i in p_word:
            if i.isalpha() and i.lower() == i:
                l_flag = 1
                break
        for i in p_word:
            if i.isalpha() and i.upper() == i:
                u_flag = 1
                break
        for i in p_word:
            if i.isdigit():
                d_flag = 1
                break
        for i in p_word:
            if not (i.isalpha() or i.isdigit()):
                s_flag = 1
                break

        if l_flag == 1 and u_flag == 1 and d_flag == 1 and s_flag == 1:
            return True
    else:
        raise CustomException.InvalidPasswordException()
Exemplo n.º 18
0
def validate_account_number(acc):
    if (acc.isdigit()):
        return 1
    else:
        raise CustomException.InvalidAcccountNumberException()
Exemplo n.º 19
0
def check_user_name(uname):
    if uname.isalpha():
        return True
    else:
        raise CustomException.InvalidUserNameException()
Exemplo n.º 20
0
def check_amount(amount):
    if(amount>0):
        return True 
    raise CustomException.InvalidAmountException()
Exemplo n.º 21
0
def check_b_password(n_password):
    if not n_password.isalnum():
        return True
    raise CustomException.InvalidPasswordException()
Exemplo n.º 22
0
def check_user_id(n_user_id):
    if(n_user_id.isalnum()):
        return True
    raise CustomException.InvalidUserNameException()
Exemplo n.º 23
0
def check_captcha(sys_cap, cap):
    if (sys_cap == cap):
        return True
    else:
        raise CustomException.InvalidCaptchaException()
Exemplo n.º 24
0
 def __init__(self):
     message = "No active database connection!"
     CustomException.__init__(self, message)
Exemplo n.º 25
0
def check_number(c_number):
    if(len(c_number)==12 and c_number.isdigit()):
        return True
    raise CustomException.CardNumberException()
Exemplo n.º 26
0
    def __init__(self, url: str, dbName: str):

        message = "Connection to database %s at %s failed!" % (url, dbName)
        CustomException.__init__(self, message)
Exemplo n.º 27
0
def check_cvv(cvv):
    if(len(cvv)==3 and cvv.isdigit()):
        return True
    raise CustomException.InvalidCvvException()
Exemplo n.º 28
0
def check_bank_name(n_name):
    list1=CheckDB.check_name()
    if(n_name.upper() in list1):
        return True
    return CustomException.InvalidCvvException()
Exemplo n.º 29
0
def check_user(mnumber, password):
    p_word = CheckDB.get_user(mnumber)
    if (p_word == password):
        return True
    else:
        raise CustomException.InvalidUserException()
Exemplo n.º 30
0
    def __init__(self, query: str):

        message = "Failed to execute the following query: %s" % query
        CustomException.__init__(self, message)