コード例 #1
0
    def _check_if_account_exists(self, user):
        # searching for a username-password match
        sql_username = "******"
        sql_password = "******"
        values = (user.get_username(), user.get_password())

        db = Database()
        results_u = db.fetchall_results(sql_username, (values[0], ))
        results_p = db.fetchall_results(sql_password, (values[1], ))
        db.close()
        # bug: ignoring the letter case with this list comprehension
        match = [(a, b) for (a, b) in results_u for (c, d) in results_p
                 if (a == c) and (b == d)]

        if len(results_u) == 0:  # username doesn't exists
            return False
        elif len(match) == 1:  # username - password match
            return True
        elif len(
                match
        ) == 0:  # username-password mis-match: password either doesn't exist in db
            while len(match) == 0:  # or it doesn't match the entered username
                print("Password incorrect. Try again.")
                user.input_password()
                pw_value = user.get_password()
                db = Database()
                results_p = db.fetchall_results(sql_password, (pw_value, ))
                match = [(a, b) for (a, b) in results_u for (c, d) in results_p
                         if (a == c) and (b == d)]
                if len(match) == 1:
                    return True
コード例 #2
0
    def show_upcoming_tasks_for_user(user_id):
        sql = "SELECT task_description, due_date, due_time, time_created " \
              "FROM tasks " \
              "JOIN users " \
              "ON tasks.user_id = users.user_id " \
              "WHERE tasks.user_id = %s AND tasks.due_date > NOW()"
        db = Database()
        tasks = db.fetchall_results(sql, (user_id, ))
        db.close()

        if len(tasks) == 0:
            return input(
                "You don't have any upcoming tasks. Would you like to create one now?\n"
                "yes\nno\n")
        else:
            count = 1
            for task in tasks:
                print("------------------------------------")
                print("TASK #", count)
                print("task description:", task[0])
                print("due date:", calendar.day_name[task[1].weekday()],
                      task[1])
                print("due_time:", task[2])
                # print("time until:", ... - datetime.now())   #  TODO feature... coming up in next sprint! :)
                print("task created on:", task[3])
                count += 1