def check_credentials(): user = request.forms.get('user', '') password = request.forms.get('password', '') if not pubsub.check_user(user, password): return show_main_page() token = secrets.token_bytes(32) logged_in_users.setdefault(token, user) response.set_cookie('token', token, max_age=cookie_max_age, secret=secret) return show_main_page(user)
def check_credentials(): user = request.forms.get('user', '') password = request.forms.get('password', '') if not pubsub.check_user(user, password): return show_main_page() token = secrets.token_bytes(32) logged_in_users.setdefault(token, user) response.set_cookie('token', token, max_age=60, secret=secret) return show_main_page(user)
def check_credentials() -> None: user = request.forms.get("user", "") password = request.forms.get("password", "") if not pubsub.check_user(user, password): return show_main_page() token = secrets.token_bytes(32) logged_in_users[token] = user response.set_cookie("token", token, max_age=60, secret=secret) return show_main_page(user)
def check_credentials(): user = request.forms.get('user', '') password = request.forms.get('password', '') if not pubsub.check_user(user, password): time.sleep(1) # Add failed message and increment failure counter return show_main_page() token = secrets.token_bytes(32) logged_in_users.setdefault(token, user) response.set_cookie('token', token, max_age=600, secret=secret) return show_main_page(user)
post_message('homer', 'Donuts?', now - 80) post_message('homer', 'Anybody here?', now - 50) post_message('homer', 'have you ever wanted to unpack mappings?', now - 46) follow('felix', followed_user='******') follow('felix', followed_user='******') follow('homer', followed_user='******') follow('homer', followed_user='******') follow('popeye', followed_user='******') if __name__ == '__main__': from pubsub import posts, followers, following, user_info from pubsub import posts_by_user, posts_for_user, search from pubsub import get_followers, get_followed, get_user, check_user, age assert check_user('felix', password='******') assert not check_user('homer', password='******') print() pprint(list(posts)) print('\nFollowers') pprint(dict(followers)) print('\nFollowing') pprint(dict(following)) print("\nUser info") pprint(user_info) print('-' * 50)
follow('raymondh', followed_user='******') follow('raymondh', followed_user='******') if __name__ == '__main__': import pubsub pubsub.save() del pubsub.posts, pubsub.user_posts, pubsub.hashtag_index, del pubsub.followers, pubsub.following, pubsub.user_info pubsub.restore() from pubsub import posts, followers, following, user_info, hashtag_index from pubsub import posts_by_user, posts_for_user, search from pubsub import get_followers, get_followed, get_user, check_user, age assert check_user('raymondh', password='******') assert not check_user('davin', password='******') print() pprint(list(posts)) print('\nFollowers') pprint(dict(followers)) print('\nFollowing') pprint(dict(following)) print("\nUser info") pprint(user_info) print('-' * 50) print('\nPosts by raymondh (3)') pprint(posts_by_user('raymondh', limit=3)) print('\nPosts for davin (6)')
post_message('barry', 'enums rock', now-20) post_message('raymondh', '#python tip: never mutate while iterating', now-10) post_message('davin', 'coriander and cilantro come from the same plant', now) follow('davin', followed_user='******') follow('davin', followed_user='******') follow('selik', followed_user='******') follow('raymondh', followed_user='******') follow('raymondh', followed_user='******') if __name__ == '__main__': from pubsub import posts, followers, following, user_info from pubsub import posts_by_user, posts_for_user, search from pubsub import get_followers, get_followed, get_user, check_user, age assert check_user('raymondh', password='******') assert not check_user('davin', password='******') print() pprint(list(posts)) print('\nFollowers') pprint(dict(followers)) print('\nFollowing') pprint(dict(following)) print("\nUser info") pprint(user_info) print('-' * 50) print('\nPosts by raymondh (3)') pprint(posts_by_user('raymondh', limit=3)) print('\nPosts for davin (6)')
import pubsub pubsub.save() del ( pubsub.posts, pubsub.user_posts, pubsub.hashtag_index, ) del pubsub.followers, pubsub.following, pubsub.user_info pubsub.restore() from pubsub import posts, followers, following, user_info, hashtag_index from pubsub import posts_by_user, posts_for_user, search from pubsub import get_followers, get_followed, get_user, check_user, age assert check_user("raymondh", password="******") assert not check_user("davin", password="******") print() pprint(list(posts)) print("\nFollowers") pprint(dict(followers)) print("\nFollowing") pprint(dict(following)) print("\nUser info") pprint(user_info) print("-" * 50) print("\nPosts by raymondh (3)") pprint(posts_by_user("raymondh", limit=3)) print("\nPosts for davin (6)")