# Path: yithlibraryserver/user/accounts.py
# def get_provider_key(provider):
#     return '%s_id' % provider


from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember
from yithlibraryserver.user.accounts import get_provider_key
    return first_name, last_name


def delete_user(db, user):
    result = db.users.remove(user['_id'], safe=True)
    return result['n'] == 1


def update_user(db, user, user_info, other_changes):
    changes = {}
    for attribute in ('screen_name', 'first_name', 'last_name', 'email'):
        if attribute in user_info and user_info[attribute]:
            if attribute in user:
                if user_info[attribute] != user[attribute]:

                    changes[attribute] = user_info[attribute]
            else:
                changes[attribute] = user_info[attribute]

    changes.update(other_changes)

    db.users.update({'_id': user['_id']}, {'$set': changes}, safe=True)


def user_from_provider_id(db, provider, user_id):
    provider_key = get_provider_key(provider)
    return db.users.find_one({provider_key: user_id})


def register_or_update(request, provider, user_id, info, default_url='/'):

# Path: yithlibraryserver/user/accounts.py
# def get_provider_key(provider):
#     return '%s_id' % provider


# Path: yithlibraryserver/user/utils.py
from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember
from yithlibraryserver.user.accounts import get_provider_key

    return first_name, last_name


def delete_user(db, user):
    result = db.users.remove(user['_id'], safe=True)
    return result['n'] == 1


def update_user(db, user, user_info, other_changes):
    changes = {}
    for attribute in ('screen_name', 'first_name', 'last_name', 'email'):
        if attribute in user_info and user_info[attribute]:
            if attribute in user:
                if user_info[attribute] != user[attribute]:

                    changes[attribute] = user_info[attribute]
            else:
                changes[attribute] = user_info[attribute]

    changes.update(other_changes)

    db.users.update({'_id': user['_id']}, {'$set': changes}, safe=True)


def user_from_provider_id(db, provider, user_id):
    provider_key = get_provider_key(provider)
    return db.users.find_one({provider_key: user_id})


def register_or_update(request, provider, user_id, info, default_url='/'):

    provider_key = get_provider_key(provider)