from user import User

users=[
User(1,'bob','asdf'),
User(2,'jim','abcd')

]

usernameMapping={u.username:u for u in users}
useridMapping={u.id:u for u in users}

def authenticate(username,password):
    user=usernameMapping.get(username,None)
    return user
def identity(payload):
    print(f"payload: {payload}")
    userId=payload['identity']
    print(f"user ID is {userId}")

    user=useridMapping.get(userId,None)

    return user

# from werkzeug.security import safe_str_cmp
# from user import User

# users = [
#     User(1, 'bob', 'asdf'),
#     User(2, 'user2', 'abcxyz'),
# ]

# username_table = {u.username: u for u in users}
# userid_table = {u.id: u for u in users}

# def authenticate(username, password):
#     user = username_table.get(username, None)
#     if user and safe_str_cmp(user.password, password):
#         return user

# def identity(payload):
#     user_id = payload['identity']
#     return userid_table.get(user_id, None)
