Example #1
0
 def login(self):
     loop_choice = 'y' or 'n'
     while loop_choice.lower() in ('y', 'yes'):
         self.choice = None
         print("_" * 54)
         print("            WELCOME TO ONLINE RETAIL SHOP")
         print("_" * 54)
         print("Please select the user type (1/2)")
         c_inp = input("\t1.Admin \n \t2.Customer \n")
         if c_inp == "1":
             Admin.login(self)
         elif c_inp == "2":
             Customer.login(self)
         print("Do You Want To Shop Again(y/n)")
         loop_choice = input()
Example #2
0
from User import User,Admin,Priviledges

user1 = Admin('mario','armario')

user1.describe_user()

user1_privileges = ['can add a post',
	 'can delete a post',
	'can ban user'
]

user1.privileges.privileges = user1_privileges
user1.privileges.show_privileges()
Example #3
0
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  7 17:21:12 2022

@author: Hank
"""

from User import Users
from User import Privileges
from User import Admin

Max = Admin('Max', 'Power', 29, 77, 205)

max_privileges = ['do all the things', 'delete user info', 'crunch on chips']

Max.privileges.privileges = max_privileges

Max.describe_user()
Max.privileges.show_privileges()
Max.greet_user()
Example #4
0
from User import User, Admin, Privileges

admin = Admin("Koe", "Elan", "12")
admin.describe_user()
admin.privileges.show_privileges()
Example #5
0
# import User class from User file
from User import User
from User import Admin

# create user object from User class
user = User("unai", "usainzg", "unai1808")

# call sayHello() method from created object
user.sayHello()

# call User class method, equals to static method call on java
User.classMethod(6)

# call to __str__ method
print(user)

# test __eq__ overrided method
uObj = User("unai", "usainzg", "123456")
print(user == uObj)

# inheritanced class object
admin = Admin("admin", "admin", "admin123", "idAdmin")
admin.printId()
def customer_menu():
    """

    :return: customer operation menu
    """
    while True:
        print("========================================\n"
              "pleas login or create admin account\n"
              "========================================\n"
              "1. create account\n"
              "2. login\n"
              "3. Active account\n"
              "4. back\n")
        choice = input('Enter choice: ')
        try:
            choice = int(choice)
        except ValueError:
            print("That's not an int!")
            continue

        if choice == 1:
            customer_info = input(
                "========================================\n"
                "please enter these information\n"
                "========================================\n"
                "your full name | an username | a password | phone number :"
            ).split('|')
            customer_exist = User.check_username(customer_info[1],
                                                 'Customers_info.csv')
            if customer_exist:
                customer = Customer(customer_info[1], customer_info[0],
                                    customer_info[2], customer_info[3])
                User.create_account(customer, 'Customers_info.csv')
            else:
                print('this username already exists!')

        elif choice == 2:
            username = input('username:'******'Customers_info.csv')
            if not customer_exist:
                cnt = 0
                while cnt < 3:
                    password = input('password:'******'Customers_info.csv', username,
                                              password)
                    if pass_correct:
                        print(f'welcome dear {username}.\n')
                        logout = False
                        while True:
                            print('========================================\n'
                                  'please select a part.\n'
                                  '========================================\n'
                                  '1. shopping\n'
                                  '2.change password\n'
                                  '3. logout\n')
                            part = input('enter a choice:')

                            try:
                                part = int(part)
                            except ValueError:
                                print("That's not an int!")
                                continue
                            if part == 1:
                                print(
                                    '\n========================================\n'
                                    'list of our products\n'
                                    '========================================\n'
                                )
                                Product.display()
                                print(
                                    '========================================\n'
                                )
                                order_list = []
                                while True:
                                    item, numbers = input(
                                        'which item(enter column number), how many : '
                                    ).split(',')
                                    order = Customer.ordering(item, numbers)
                                    if order is False:
                                        print('Inventory is not enough!')
                                    else:
                                        order_list.append(order)
                                        select = int(
                                            input(
                                                '1 - continue | 2 - finish :'))
                                        if select == 2:
                                            break
                                df = pd.DataFrame(order_list,
                                                  columns=[
                                                      'name', 'brand',
                                                      'price(for one)',
                                                      'number', 'total price'
                                                  ])
                                total_price = sum(
                                    [x['total price'] for x in order_list])
                                print('-' * 92)
                                print(f'your order list :\n{df}')
                                print('-' * 53)
                                print(f'your total price is : {total_price}')
                                print('-' * 92)

                                confirm = int(
                                    input('1 - confirm | 2 - discard :'))
                                if confirm == 1:
                                    my_logger.info('new invoice',
                                                   exc_info=True)
                                    Product.update_inventory(order_list)
                                    Product.record_orders(
                                        order_list, username, total_price)

                            elif part == 2:
                                old_pass = hashlib.md5(
                                    input('enter password:'******'enter new password:'******'Customers_info.csv', username,
                                                old_pass, new_pass)
                                my_logger.info('customer change password',
                                               exc_info=True)

                            elif part == 3:
                                logout = True
                                break
                            else:
                                print('Invalid input.\n')
                        if logout:
                            break
                    else:
                        print('password is wrong. please try again.')
                        cnt += 1
                if cnt == 3:
                    change_status = Admin.change_status(
                        username, 'Deactivate', 'Customers_info.csv')
                    if change_status:
                        my_logger.info('locked user', exc_info=True)
                        print(
                            'your account is locked. please send request to admin.'
                        )
            else:
                print(
                    'this username does not exist. please create an account.')
        elif choice == 3:
            username = input('username:'******'Customers_info.csv')
            if not customer_exist:
                change_status = Admin.change_status(username, 'Active',
                                                    'Customers_info.csv')
                if change_status:
                    my_logger.info('active user', exc_info=True)
                    print('your account is active now. please login.')
        elif choice == 4:
            break
        else:
            print('Invalid input.\n')
from User import Admin

admin = Admin('Karandeep', 'Bhardwaj', 'Male', '*****@*****.**')
admin.privilege.show_privileges()
def admin_menu():
    """

    :return: admin operation menu
    """
    while True:
        print("========================================\n"
              "pleas login or create admin account\n"
              "========================================\n"
              "1. create account\n"
              "2. login\n"
              "3. back\n")

        choice = input("Enter choice: ")

        try:
            choice = int(choice)
        except ValueError:
            print("That's not an int!")
            continue

        if choice == 1:
            while True:
                admin_identify = input('\nplease enter admin identity code :')
                if admin_identify == Admin.admins_identification:
                    user_info = input(
                        "========================================\n"
                        "please enter these information\n"
                        "========================================\n"
                        "your full name | an username | a password :"******"That's not an int!")
                                continue

                            if part == 1:
                                while True:
                                    product_info = input(
                                        'barcode | name | brand | price | stock :'
                                    ).split('|')
                                    insertion = Admin.add_product(product_info)
                                    if insertion:
                                        my_logger.info('new product added',
                                                       exc_info=True)
                                        if int(
                                                input(
                                                    '1 - new product | 2 - finish :'
                                                )) == 2:
                                            break
                            elif part == 2:
                                Admin.view_invoices()

                            elif part == 3:
                                old_pass = hashlib.md5(
                                    input('enter password:'******'enter new password:'******'Admin_info.csv', username,
                                                old_pass, new_pass)
                                my_logger.info('admin change password',
                                               exc_info=True)

                            elif part == 4:
                                logout = True
                                break
                            else:
                                print('Invalid input.\n')
                        if logout:
                            break
                    else:
                        print('password is wrong. please try again.')
            else:
                print(
                    'this username does not exist. please create an account.')
        elif choice == 3:
            break
        else:
            print('Invalid input.\n')