def login_to_dict(login):
    """Creates a Python dict for a Login database entity.

    This is not a method of the Login model because it is not normally needed
    by the Liblio server. It's admin-only, so it can be considered private to
    this controller.

    Note: This does expose user email addresses, so use with care. Passwords
    are not returned, but they're stored as hashes anyway.
    """
    return dict(
        id=login.id,
        username=login.username,
        email=login.email,
        last_login=login.last_login,
        last_action=login.last_action,
        role=login.role.name,
        userdata=login.user.to_dict()
    )