Пример #1
0
func (p *InMemoryDataStore) DeleteExternalUserAccount(user *dm.ExternalUser) (*dm.ExternalUser, error) {
	if user == nil {
		return nil, nil
	}
	if user.Id == "" {
		return user, dm.ERR_MUST_SPECIFY_ID
	}
	oldUserI, _ := p.retrieve(_INMEMORY_EXTERNAL_USER_ACCOUNT_COLLECTION_NAME, user.Id)
	var oldUser *dm.ExternalUser = nil
	if oldUserI != nil {
		oldUser = oldUserI.(*dm.ExternalUser)
	}
	if oldUser != nil {
		if err := user.BeforeDelete(); err != nil {
			return user, err
		}
		p.delete(_INMEMORY_EXTERNAL_USER_ACCOUNT_COLLECTION_NAME, user.Id)
		p.removeFromStringMapCollection(user.Id, _INMEMORY_EXTERNAL_ACCOUNT_IDS_FOR_CONSUMER_ID_COLLECTION_NAME, oldUser.ConsumerId, user.Id)
		p.removeFromStringMapCollection(user.Id, _INMEMORY_EXTERNAL_ACCOUNT_IDS_FOR_EXTERNAL_USER_ID_COLLECTION_NAME, oldUser.ExternalUserId, user.Id)
		if err := user.AfterDelete(); err != nil {
			return user, err
		}
	}
	return user, nil
}
Пример #2
0
func (p *InMemoryDataStore) CreateExternalUserAccount(user *dm.ExternalUser) (*dm.ExternalUser, error) {
	if user == nil {
		return nil, nil
	}
	if user.Id == "" {
		user.Id = p.generateIdForAccount(_INMEMORY_EXTERNAL_USER_ACCOUNT_COLLECTION_NAME)
	}
	if _, ok := p.retrieve(_INMEMORY_EXTERNAL_USER_ACCOUNT_COLLECTION_NAME, user.Id); ok {
		return user, ba.ERR_ACCOUNT_ALREADY_EXISTS_WITH_SPECIFIED_ID
	}
	if err := user.BeforeCreate(); err != nil {
		return user, err
	}
	if err := user.BeforeSave(); err != nil {
		return user, err
	}
	p.store(user.Id, _INMEMORY_EXTERNAL_USER_ACCOUNT_COLLECTION_NAME, user.Id, user)
	p.addToStringMapCollection(user.Id, _INMEMORY_EXTERNAL_ACCOUNT_IDS_FOR_CONSUMER_ID_COLLECTION_NAME, user.ConsumerId, user.Id, user.Id)
	p.addToStringMapCollection(user.Id, _INMEMORY_EXTERNAL_ACCOUNT_IDS_FOR_EXTERNAL_USER_ID_COLLECTION_NAME, user.ExternalUserId, user.Id, user.Id)
	if err := user.AfterSave(); err != nil {
		return user, err
	}
	if err := user.AfterCreate(); err != nil {
		return user, err
	}
	return user, nil
}