Exemplo n.º 1
0
def main():
    """
    this method is used to call main menu for login
    """
    conn = ConnectDb()
    try:
        os.system('clear')
        # select role for login
        print("login as:\n")
        menu = Menu()
        roles = [x.name for x in Role]
        roles.extend([str(BackButton.EXIT.name)])
        role = menu.draw_menu(roles)
        role_id = Role[role].value
        input()

        # get user name and password for login
        user_name = input("enter user name: ")
        password = getpass()

        # check user authentication
        result = conn.get_user_with_role(user_name, role_id)
        flag = True
        if result is not None:
            os.system('clear')
            actual_pass = decrypt_pass(result[1])
            if str(actual_pass.decode("utf-8")) == password:
                flag = False
                if role_id == int(Role.BDO.value):
                    bdo = BDO()
                    bdo.bdo_id = result[0]
                    bdo.bdo_features()
                elif role_id == int(Role.GPM.value):
                    gpm = GPM()
                    gpm.gpm_id = result[0]
                    gpm.gpm_features()
                elif role_id == int(Role.Member.value):
                    member = Member()
                    member.member_id = result[0]
                    member.member_features()
        if result is None or flag:
            print(Color.F_Red + 'wrong credentials' + Base.END)
            input()
            main()

    except Exception as e:
        print(e)
        sys.exit()
    finally:
        conn.close_conn()
Exemplo n.º 2
0
    def show_members(self):
        """
            this method is used to print all members of current gpm.
        """
        details_cursor = self.conn.get_subordinate_details(self.gpm_id)
        members_list = details_cursor.fetchall()
        if len(members_list) == 0:
            print(Color.F_Green + "you don't have any member under you" + Base.END)
            return
        # converting list of tuples into list of list
        list_data = [list(elem) for elem in members_list]
        for member in list_data:
            member[2] = decrypt_pass(member[2])

        raw_data_to_table(list_data, details_cursor)
Exemplo n.º 3
0
 def show_gpm(self):
     """
     this method is used to print all gpm of current bdo.
     """
     print("GPM's list:\n")
     result = self.conn.get_subordinate_details(self.bdo_id)
     data = result.fetchall()
     if len(data) == 0:
         print(Color.F_Green + "you don't have any GPM under you" +
               Base.END)
         return
     # converting list of tuples into list of list
     list_data = [list(elem) for elem in data]
     for gpm in list_data:
         gpm[2] = decrypt_pass(gpm[2])
     raw_data_to_table(list_data, result)
Exemplo n.º 4
0
    def view_details(self):
        """
            this method is used to print member details on console.
        """
        member_details = self.conn.get_member_details(self.member_id)
        if member_details is None:
            print("you are not longer part of this system")
            input()
            sys.exit()
        project_details = self.conn.get_member_project(self.member_id)
        password = decrypt_pass(member_details[1])
        # printing personal details
        print(Base.BOLD + "Personal Details" + Base.END + "\n")
        print("Name: " + Color.F_Green + member_details[4] + Base.END)
        print("Password: "******"User name: " + Color.F_Green + member_details[2] + Base.END)
        print("Created at: " + Color.F_Green + member_details[3] + Base.END)
        print("State: " + Color.F_Green + member_details[5] + Base.END)
        print("District: " + Color.F_Green + member_details[6] + Base.END)
        print("Pincode: " + Color.F_Green + str(member_details[7]) + Base.END)
        print("Age: " + Color.F_Green + str(member_details[8]) + Base.END)
        print("Gender: " + Color.F_Green + member_details[9] + Base.END)
        print("Assigned Gram Panchayat Member: " + Color.F_Green +
              member_details[10] + Base.END + "\n")

        # printing member project details
        print(Base.BOLD + "Project Details" + Base.END + "\n")
        if project_details is None:
            print(Color.F_Red + "you are not assigned to any project\n" +
                  Base.END)
        else:
            duration = datetime.datetime.now() - datetime.datetime.strptime(
                str(project_details[0]), '%Y-%m-%d')
            wage = duration.days * 100
            print("Project Name: " + Color.F_Green + project_details[1] +
                  Base.END)
            print("assigned Date: " + Color.F_Green + project_details[0] +
                  Base.END)
            print("Project Type: " + Color.F_Green + project_details[2] +
                  Base.END)
            print("Total working days: " + Color.F_Green + str(duration) +
                  Base.END)
            print("Total wage: " + Color.F_Green + str(wage) + Base.END)
Exemplo n.º 5
0
 def test_decrypt_pass(self, mock_decrypt):
     result = decrypt_pass('sample_cipher')
     mock_decrypt.assert_called_once()
     self.assertEqual('dummy', result)
Exemplo n.º 6
0
 def test_decrypt_pass(self, mock_decode, mock_decrypt):
     encoded_cipher = 'sample_password'
     mock_decrypt.return_value = 'encrypted value'
     decrypt_pass(encoded_cipher)
     mock_decode.assert_called_once_with(encoded_cipher)
     mock_decrypt.assert_called_once()
Exemplo n.º 7
0
def main():
    """
    this method is used to call main menu for login
    """
    conn = ConnectDb()
    try:
        os.system('clear')
        # select role for login
        print("login as:\n")
        menu = Menu()
        roles = [x.name for x in Role]
        roles.extend([str(BackButton.EXIT.name)])
        role = menu.draw_menu(roles)
        role_id = Role[role].value
        input()

        # get user name and password for login
        user_name = input("enter user name: ")
        password = getpass()

        # check user authentication
        result = conn.get_user_info(user_name)
        flag = True
        auth_flag = True
        if result is not None:
            os.system('clear')
            actual_pass = decrypt_pass(result[1].encode())
            if actual_pass == password:
                flag = False
                if role_id == int(Role.EMPLOYEE.value):
                    auth_flag = False
                    emp = Employee()
                    emp.employee_id = result[0]
                    emp.employee_features()
                else:
                    user_role = conn.get_user_role(result[0], role_id)
                    if user_role is not None:
                        auth_flag = False
                        if role_id == int(Role.SUPERVISOR.value):
                            pass
                            supervisor = Supervisor()
                            supervisor.supervisor_id = result[0]
                            supervisor.supervisor_features()
                        elif role_id == int(Role.ADMIN.value):
                            pass
                            member = Admin()
                            member.admin_id = result[0]
                            member.admin_features()
        if flag:
            print(Color.F_Red + 'wrong credentials' + Base.END)
            input()
            main()
        if auth_flag:
            print(Color.F_Red + 'you are not authorized' + Base.END)
            input()
            main()

    except Exception as e:
        print(e)
        sys.exit()
    finally:
        conn.close_conn()