Esempio n. 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']
Esempio n. 2
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')
Esempio n. 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')
Esempio n. 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()
Esempio n. 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()
Esempio n. 6
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
Esempio n. 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
Esempio n. 8
0
def set_organization(allocates: list):
    for allocate in allocates:
        with suppress(UserNotFound, KeyError):
            allocate['toOrganization'] = AccountDomain.get_one(
                allocate['to'])['organization']
Esempio n. 9
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']
Esempio n. 10
0
def set_organization(allocates: list):
    for allocate in allocates:
        with suppress(UserNotFound, KeyError):
            allocate['toOrganization'] = AccountDomain.get_one(allocate['to'])['organization']