Esempio n. 1
0
def check_user_exists(username, state):
    stored_username = custom_hash(username)
    file_path = instance_path(state)
    open(file_path, 'a').close()
    with open(file_path, 'r+') as file:
        return re.search(
            '^{0}'.format(re.escape(stored_username)), file.read(), flags=re.M)
Esempio n. 2
0
def getpid(username):
    file_path = instance_path(state)

    if not os.path.isfile(file_path):
        return

    stored_username = custom_hash(username)
    with open(file_path) as oldfile:
        for line in oldfile:
            if stored_username in line:
                return line.split(':')[1].strip()
Esempio n. 3
0
def add_new_user_instance(username):
    file_path = instance_path(state)
    if not check_user_exists(username):
        stored_username = custom_hash(username)
        with open(file_path, "a+") as instance_file:
            redacted_list = [username]
            instance_file = RedactedFile(instance_file, redacted_list)
            instance_file.write("{0} : {1}\n".format(stored_username,
                                                     os.getpid()))
        return True
    return False
Esempio n. 4
0
def welcome_message():
    new_message = Message()

    new_message \
        .add("👋 Welcome to the Grade Notifier 🚨") \
        .newline() \
        .newline() \
        .add("Your UID is: {0}".format(custom_hash(user.get_username()))) \
        .newline() \
        .add("You're all set up. You should see your current grades below!") \
        .newline() \
        .add("The notifier will message you whenever a grade changes (or is added)!") \
        .newline()
    return new_message
Esempio n. 5
0
def remove_user_instance(username):
    file_path = instance_path(state)
    file = ""

    if not os.path.isfile(file_path):
        return

    stored_username = custom_hash(username)
    with open(file_path) as oldfile:
        for line in oldfile:
            if stored_username not in line:
                file += line
    with open(file_path, 'w+') as newfile:
        redacted_list = [username]
        newfile = RedactedFile(newfile, redacted_list)
        newfile.writelines(file)
Esempio n. 6
0
def kill(username):
    stored_username = custom_hash(username)
    pid = getpid(stored_username)
    if pid:
        subprocess.run(['kill', '-SIGINT', pid])
Esempio n. 7
0
 def test_custom_hash_different_users(self):
     username1 = 'foo'
     username2 = 'bar'
     self.assertNotEqual(custom_hash(username1), custom_hash(username2))
Esempio n. 8
0
 def test_custom_hash_constant_results(self):
     username = '******'
     expected_hash = 'e4af8b9ab44a126630815144bc6412ad113f5dd94ac59e6aa1fef60b954bf5c9'
     actual_hash = custom_hash(username)
     self.assertEqual(expected_hash, actual_hash)
Esempio n. 9
0
 def test_custom_hash_case_insensitive(self):
     username1 = 'FOO'
     username2 = 'fOO'
     self.assertEqual(custom_hash(username1), custom_hash(username2))