Exemple #1
0
 public async Task <IActionResult> RegisterUser([FromBody] UserCreateDataRepresentation data)
 {
     return((await _userStore.Create(
                 TrustDefaults.KnownRootIdentifier,
                 TrustDefaults.KnownHomeResourceId,
                 data.FromRepresentation(),
                 Permission.FullControl | Permission.Owner,
                 CallerCollectionRights.User
                 ))
            .MakeUserUri(Url)
            .MakeCreated());
 }
 /// <summary>
 ///     Reverse map with validation across-the-wire representation into in-memory representation
 /// </summary>
 public static UserCreateData FromRepresentation(this UserCreateDataRepresentation data)
 {
     return(new UserCreateData
     {
         Name = data.Name
                .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A user requires a name"),
         Email = data.Email
                 .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A user requires an email"),
         ExternalId = data.ExternalId
                      .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A user requires an external id")
     });
 }
Exemple #3
0
        public async Task <IActionResult> RegisterUser([FromBody] UserCreateDataRepresentation data, string id)
        {
            (await _tenantStore.Get(id))
            .ThrowObjectNotFoundExceptionIfNull("Invalid tenant");

            var user = await _userStore.GetByExternalId(data.ExternalId);

            // Create the user if it doesn't already exist
            if (user.IsNull() || user.Id.IsNullOrWhitespace())
            {
                // make the user
                var userId = await _userStore.Create(
                    User.GetId(),
                    id,
                    data.FromRepresentation(),
                    Permission.FullControl,
                    CallerCollectionRights.User);

                // and stick it on the tenant
                await _tenantStore.IncludeUser(id, userId, Permission.Get, CallerCollectionRights.Tenant);

                Log.DebugFormat("New user {0} registered on tenant {1}", userId, id);

                // now, we have the identity user, link this into the new user
                return(userId
                       .MakeUserUri(Url)
                       .MakeCreated());
            }

            // 409 if already on the tenant
            (await _tenantStore.IsRegisteredOnTenant(id, user.Id))
            .ThrowInvalidOperationExceptionIf(exists => exists, "User already exists on tenant");

            // 202 if now included
            await _tenantStore.IncludeUser(id, user.Id, Permission.Get, CallerCollectionRights.Tenant);

            Log.DebugFormat("Registered existing user {0} on tenant {1}", user.Id, id);

            return(user.Id
                   .MakeUserUri(Url)
                   .MakeAccepted());
        }