Beispiel #1
0
def login():
    util.clear()
    print("\u001b[33;1m+----------------------------------------------------+")
    print(
        "|\u001b[32m                   Login Account                    \u001b[33;1m|"
    )
    print("+----------------------------------------------------+")

    print("\u001b[31;1mEnter your username:"******"\u001b[34;1m> ")

    print("\u001b[31;1mEnter Your Password:"******"\u001b[34;1m> ")

    db.execute(
        "select * from users where username = %s and password = SHA1(%s)",
        (username, password))
    result = db.fetchone()

    if result != None:
        dashboard.displayMenu(result[0])

    else:
        print("Incorrect Username/Password !!")
        input("\nPress Any Key to Continue ...")
Beispiel #2
0
def getBalance(uid):
    db.execute("SELECT * FROM transactions WHERE user_id = %s", (uid,))
    result = db.fetchall()

    balance = 0
    for i in result:
        if i[2] == "DEPOSIT":
            balance += i[3]

        else:
            balance -= i[3]

    return balance
Beispiel #3
0
def deposit(uid):
    try:
        print("\nEnter Amount for Deposit:")
        amount = float(input("> "))

        db.execute("INSERT INTO transactions (user_id, type, amount) VALUES (%s, %s, %s)",
                   (uid, "DEPOSIT", amount))
        connection.commit()
        checkBalance(uid)

    except:
        print("Enter amount only !!")
        input("\nPress Any Key to Continue ...")
Beispiel #4
0
def miniStatement(uid):
    db.execute("SELECT * FROM transactions WHERE user_id = %s", (uid,))
    result = db.fetchall()

    balance = 0
    print("+-----------+---------------+-------------------+")
    print("| Date      |  Time         |  WITHDRAW,DEPOSIT |")
    print("+-----------+---------------+-------------------+")
    for i in result:
        if i[2] == "DEPOSIT":
            print(f"\u001b[34;1m|\u001b[35m {i[4]} \u001b[34;1m      |\u001b[31;1m    - Rs {i[3]} \u001b[34;1m")
            print("+-----------+---------------+-------------------+")
        else:
            print(f"\u001b[34;1m|\u001b[35m {i[4]}\u001b[34;1m       |\u001b[32m    + Rs {i[3]} \u001b[34;1m")
            print("+-----------+---------------+-------------------+")

    input("\nPress Any Key to Continue ...")
Beispiel #5
0
def withdraw(uid):
    try:
        print("\nEnter Amount for Withdraw:")
        amount = float(input("> "))
        
        if amount > getBalance(uid):
            print("Insufficiant balance !!")
            

    except:
        print("Enter amount only !!")
        input("\nPress Any Key to Continue ...")

    else:
        db.execute("INSERT INTO transactions (user_id, type, amount) VALUES (%s, %s, %s)",
                   (uid, "WITHDRAW", amount))
        connection.commit()
    checkBalance(uid)
Beispiel #6
0
def displayMenu(userId):
    while True:
        util.clear()
        db.execute(
                "select * from users where id = %s ", (userId,))
        user = db.fetchone()
        print(
            "\u001b[33;1m+----------------------------------------------------+")
        print(
            f"\u001b[34;1m                 Welcome { user[1] }               \u001b[33;1m ")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 1.Check Balance                                   \u001b[33;1m |")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 2.Deposit                                          \u001b[33;1m|")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 3.Withdraw                                         \u001b[33;1m|")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 4.Logout                                           \u001b[33;1m|")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 5.Profile                                         \u001b[33;1m |")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 6.Mini Statement                                   \u001b[33;1m|")
        print("+----------------------------------------------------+")
        print(
            "|\u001b[32m 7.Exit                                             \u001b[33;1m|")
        print("+----------------------------------------------------+")
        print("\u001b[31;1m\nEnter your choice: \u001b[36m")

        try:
            choice = int(input("> "))
            
            if choice == 1:
                checkBalance(user[0])

            elif choice == 2:
                deposit(user[0])

            elif choice == 3:
                withdraw(user[0])

            elif choice == 4:
                break
            
            elif choice == 5:
                profile(userId)

            elif choice == 6:
                miniStatement(userId)

            elif choice == 7:
                util.clear()
                exit()

            else:
                print("Invalid choice selected !!")
                input("\nPress Any Key to Continue ...")

        except ValueError:
            print("Invalid choice selected !!")
            input("\nPress Any Key to Continue ...")
Beispiel #7
0
def register():
    util.clear()

    print("\u001b[33;1m+----------------------------------------------------+")
    print(
        "|\u001b[32m                   Create Account                   \u001b[33;1m|"
    )
    print("+----------------------------------------------------+")

    print("\u001b[32m\nEnter your first name:")
    firstName = input("\u001b[34;1m> ")

    print("\u001b[32m\nEnter your last name:")
    lastName = input("\u001b[34;1m> ")

    while True:
        print("\u001b[32m\nEnter your Username:"******"\u001b[34;1m> ")

        db.execute("SELECT * FROM users WHERE username = %s", (username, ))
        result = db.fetchone()

        if result != None:
            print("\u001b[31;1mUsername is already registered !!")

        else:
            break

    while True:
        print("\u001b[32m\nEnter your gender(M/F):")
        gender = input("\u001b[34;1m> ")

        gender = gender.upper()
        if gender == "M" or gender == "F":
            break

        else:
            print("\u001b[31;1mGender can be either M or F !!")

    while True:
        print("\u001b[32m\nEnter your age:")
        age = input("\u001b[34;1m> ")

        try:
            age = int(age)

            if age < 13:
                print("\u001b[31;1mAge should be atleast 13 Years !!")

            elif age > 139:
                print("\u001b[31;1mAge must be less then 140 Years !!")

            else:
                break

        except:
            print("\u001b[31;1mAge must be number !!")

    while True:
        print("\u001b[32m\nEnter Phone number:")
        phone = input("\u001b[34;1m> ")

        try:
            if len(phone) == 10:
                db.execute("SELECT * FROM users WHERE phone = %s", (phone, ))
                result = db.fetchone()

                if result != None:
                    print("\u001b[31;1mPhone number is already registered !!")

                else:
                    break

            else:
                print("\u001b[31;1mPlease enter a valid phone number !!")

        except:
            print("\u001b[31;1mPlease enter a valid phone number !!")

    print("\u001b[32m\nEnter Your city:")
    city = input("> ")

    while True:
        print("\u001b[32m\nEnter your password:"******"\u001b[34;1m> ")

        if len(password) < 5:
            print("\u001b[31;1mPassword must be greater than 5 characters !!")

        else:

            break
    values = (username, firstName, lastName, gender, age, phone, city,
              password)

    db.execute(
        "INSERT INTO abc_bank.users( username, first_name, last_name, gender, age, phone, city, password ) VALUES ( %s, %s, %s, %s, %s, %s, %s, SHA1(%s) )",
        values)
    connection.commit()

    input("\u001b[32m\nPress Any Key to Continue ...")
Beispiel #8
0
def profile(userId):
    while True:
        clear()
        db.execute("select * from users where id = %s ", (userId, ))
        user = db.fetchone()
        print(
            "\u001b[33;1m+----------------------------------------------------+"
        )
        print(f"|\u001b[32m  1. Change your Username | { user[1] } ")
        print(
            "\u001b[33;1m+--------------------------+--------------------------+"
        )
        print(f"|\u001b[32m  2. Change your Gender   | { user[4] } ")
        print(
            "\u001b[33;1m+--------------------------+--------------------------+"
        )
        print(f"|\u001b[32m  3. Change your Age      | { user[5] } ")
        print(
            "\u001b[33;1m+--------------------------+--------------------------+"
        )
        print(f"|\u001b[32m  4. Change your City     | { user[7] } ")
        print(
            "\u001b[33;1m+--------------------------+--------------------------+"
        )
        print(f"|\u001b[32m  5. Change Your Phone No | { user[6] } ")
        print(
            "\u001b[33;1m+----------------------------------------------------+"
        )
        print(f"|\u001b[32m  6. Change your Password <0>")
        print(
            "\u001b[33;1m+----------------------------------------------------+"
        )
        print(f"|\u001b[32m  7. Back")
        print(
            "\u001b[33;1m+----------------------------------------------------+"
        )
        print("\u001b[31;1mEnter your choice: ")
        answer = int(input("\u001b[34;1m> "))
        try:
            if answer == 1:
                print("Enter your username")
                input_user = input("> ")
                db.execute("SELECT * FROM users WHERE username = %s",
                           (input_user, ))
                result = db.fetchone()

                if result != None:
                    print("\u001b[31;1mUsername is already registered !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

                else:
                    db.execute(
                        "UPDATE users SET username = %s where username = %s ",
                        (input_user, f"{user[1]}"))

            elif answer == 2:
                print("Enter your Gender (M/F)")
                input_user = input("> ")
                input_user = input_user.upper()
                if input_user == "M" or "F":
                    db.execute(
                        "UPDATE users SET gender = %s where username = %s ",
                        (input_user, f"{user[1]}"))
                    connection.commit()

                else:
                    print("\u001b[31;1mPlease enter a valid Gender !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

            elif answer == 3:
                print("Enter your Age ")
                input_user = int(input("> "))
                if input_user < 13:
                    print("\u001b[31;1mAge should be atleast 13 Years !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

                elif input_user > 139:
                    print("\u001b[31;1mAge must be less then 140 Years !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

                else:
                    db.execute(
                        "UPDATE users SET age = %s where username = %s ",
                        (input_user, f"{user[1]}"))
                    connection.commit()

            elif answer == 4:
                print("Enter your City")
                input_user = input("> ")
                db.execute("UPDATE users SET city = %s where username = %s ",
                           (input_user, f"{user[1]}"))
                connection.commit()

            elif answer == 5:
                print("Enter your Phone No ")
                input_user = int(input("> "))
                try:
                    if len(input_user) == 10:
                        db.execute("SELECT * FROM users WHERE phone = %s",
                                   (input_user, ))
                        result = db.fetchone()
                        connection.commit()

                        if result != None:
                            print(
                                "\u001b[31;1mPhone number is already registered !!"
                            )
                            input(
                                "\nPress Any Key to Continue ...\u001b[34;1m")

                        else:
                            db.execute(
                                "UPDATE users SET phone = %s where username = %s ",
                                (input_user, f"{user[1]}"))
                            connection.commit()

                    else:
                        print(
                            "\u001b[31;1mPlease enter a valid phone number !!")
                        input("\nPress Any Key to Continue ...\u001b[34;1m")

                except:
                    print("\u001b[31;1mPlease enter a valid phone number !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

            elif answer == 6:
                print("Enter Your Password: "******"> ")
                print("Enter Retype Your Password: "******"> ")

                if passwordOne == passwordSec and len(passwordOne):
                    print("\u001b[32mPassword changed .\u001b[34;1m")
                    db.execute(
                        "UPDATE users SET password = SHA1(%s) WHERE username = %s",
                        (passwordOne, user[1]))
                    connection.commit()

                else:
                    print("\u001b[31;1mPassword dosen`t match !!")
                    print("Try again !!")
                    input("\nPress Any Key to Continue ...\u001b[34;1m")

            elif answer == 7:
                break

            else:
                print("\u001b[31;1mInvalid choice selected !!")
                input("\nPress Any Key to Continue ...\u001b[34;1m")

        except:
            print("\u001b[31;1mInvalid choice selected !!")
            input("\nPress Any Key to Continue ...\u001b[34;1m")