예제 #1
0
def set_organization(deallocates: list):
    for deallocate in deallocates:
        with suppress(
                UserNotFound,
                KeyError):  # todo ensure organization is not always needed
            deallocate['fromOrganization'] = AccountDomain.get_one(
                deallocate['from'])['organization']
예제 #2
0
파일: hooks.py 프로젝트: eReuse/DeviceHub
def set_organization(receives: list):
    """
    This method needs to execute after add_or_get_inactive_account
    :param receives:
    :return:
    """
    for receive in receives:
        with suppress(UserNotFound):
            receive['receiverOrganization'] = AccountDomain.get_one(receive['receiver']).get('organization')
예제 #3
0
def set_organization(receives: list):
    """
    This method needs to execute after add_or_get_inactive_account
    :param receives:
    :return:
    """
    for receive in receives:
        with suppress(UserNotFound):
            receive['receiverOrganization'] = AccountDomain.get_one(
                receive['receiver']).get('organization')
예제 #4
0
def login():
    """
    Performs a login. We make this out of eve, being totally open.
    :return:
    """
    try:
        account = AccountDomain.get_one({'email': request.json['email']})
        if not AccountDomain.verify_password(request.json['password'], account['password']):
            raise WrongCredentials()
        account['token'] = AccountDomain.hash_token(account['token'])
        account['_id'] = str(account['_id'])
        return jsonify(account)
    except (KeyError, TypeError, UserNotFound):
        raise WrongCredentials()
예제 #5
0
def login():
    """
    Performs a login. We make this out of eve, being totally open.
    :return:
    """
    try:
        account = AccountDomain.get_one({'email': request.json['email']})
        if not AccountDomain.verify_password(request.json['password'],
                                             account['password']):
            raise WrongCredentials()
        account['token'] = AccountDomain.hash_token(account['token'])
        account['_id'] = str(account['_id'])
        return jsonify(account)
    except (KeyError, TypeError, UserNotFound):
        raise WrongCredentials()
예제 #6
0
파일: hooks.py 프로젝트: eReuse/DeviceHub
def _add_or_get_inactive_account_id(event, field_name):
    """
    We need to execute after insert and insert_resource.
    """
    if field_name in event and type(event[field_name]) is dict:
        try:
            # We look for just accounts that share our database
            _id = AccountDomain.get_one(
                {
                    "email": event[field_name]["email"]
                    # 'databases': {'$in': AccountDomain.actual['databases']} todo review this
                }
            )["_id"]
        except UserNotFound:
            event[field_name]["databases"] = [AccountDomain.get_requested_database()]
            event[field_name]["active"] = False
            event[field_name]["@type"] = "Account"
            _id = execute_post_internal("accounts", event[field_name], True)["_id"]
        event[field_name] = _id
예제 #7
0
def _add_or_get_inactive_account_id(event, field_name):
    """
    We need to execute after insert and insert_resource.
    """
    if field_name in event and type(event[field_name]) is dict:
        try:
            # We look for just accounts that share our database
            _id = AccountDomain.get_one({
                'email': event[field_name]['email']
                # 'databases': {'$in': AccountDomain.actual['databases']} todo review this
            })['_id']
        except UserNotFound:
            event[field_name]['databases'] = [
                AccountDomain.get_requested_database()
            ]
            event[field_name]['active'] = False
            event[field_name]['@type'] = 'Account'
            _id = execute_post_internal('accounts', event[field_name],
                                        True)['_id']
        event[field_name] = _id
예제 #8
0
def set_organization(allocates: list):
    for allocate in allocates:
        with suppress(UserNotFound, KeyError):
            allocate['toOrganization'] = AccountDomain.get_one(
                allocate['to'])['organization']
예제 #9
0
파일: hooks.py 프로젝트: eReuse/DeviceHub
def set_organization(deallocates: list):
    for deallocate in deallocates:
        with suppress(UserNotFound, KeyError):  # todo ensure organization is not always needed
            deallocate['fromOrganization'] = AccountDomain.get_one(deallocate['from'])['organization']
예제 #10
0
파일: hooks.py 프로젝트: eReuse/DeviceHub
def set_organization(allocates: list):
    for allocate in allocates:
        with suppress(UserNotFound, KeyError):
            allocate['toOrganization'] = AccountDomain.get_one(allocate['to'])['organization']