コード例 #1
0
        public void Resend(int userId)
        {
            var userDomain = _usersGateway.GetUserById(userId);

            if (userDomain == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = $"A user with the supplied ID of '{userId}' could not be found"
                      }
            }
            ;

            _authenticateGateway.ResendVerification(new ConfirmationResendRequest {
                Email = userDomain.Email
            });
        }
    }
コード例 #2
0
        public void Execute(int userId)
        {
            var user = _usersGateway.GetUserById(userId);

            if (user == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = $"A user with the provided ID={userId} does not exist"
                      }
            }
            ;

            if (_authenticateGateway.DeleteUser(user.Email))
            {
                _sessionsGateway.RemoveSessions(user.Id);
                _userOrganisationGateway.DeleteUserOrganisationLink(user.Id);
                _usersGateway.ClearUserRoles(user.Id);
                _usersGateway.SetUserStatus(user, UserStatus.Deleted);
            }
        }
    }
コード例 #3
0
        public UserResponse Execute(int userId, UserUpdateRequest updateRequest)
        {
            ValidateRequestParams(updateRequest);
            var userDomain = _usersGateway.GetUserById(userId);

            // We do not store the password in the API database so cannot tell here
            // if a different value was provided compared to the current value.
            // Hence need to call the Update Password method on the authentication
            // gateway every time
            if (updateRequest.Password != null)
            {
                _authenticateGateway.AdminChangePassword(new ResetPasswordQueryParams()
                {
                    Email    = userDomain.Email,
                    Password = updateRequest.Password
                });
            }

            // if the user has passed a null value for any of the below we assume
            // they do not want that field to be updated (keep the current value)
            userDomain.CreatedAt = updateRequest.CreatedAt ?? userDomain.CreatedAt;
            userDomain.Name      = updateRequest.Name ?? userDomain.Name;
            userDomain.Status    = updateRequest.Status ?? userDomain.Status;

            // Set up the user roles provided
            userDomain = PopulateDomainWithUserRoles(userDomain, updateRequest.Roles);
            _usersGateway.UpdateUserAndRoles(userDomain);

            var associatedOrg = _usersGateway.GetAssociatedOrganisation(userId);

            // If the client has specified a non-null organisation id, create or update the association
            // (note: db schema and EF code allows many-to-many associations between users and organisations
            // but the MVP version of the front end does not allow or expect this behaviour at the moment)
            if (updateRequest.OrganisationId.HasValue)
            {
                if (associatedOrg == null)
                {
                    // create a new association
                    associatedOrg = _usersGateway.AssociateUserWithOrganisation(userId, updateRequest.OrganisationId.Value);

                    if (associatedOrg == null)
                    {
                        throw new UseCaseException()
                              {
                                  UserErrorMessage = "Could not create an association from the user to the specified organisation"
                              };
                    }
                }
                else
                {
                    associatedOrg = _usersGateway.AssociateUserWithOrganisation(userDomain.Id, updateRequest.OrganisationId.Value);
                }
            }
            else
            {
                // null value indicates the caller would like to clear the users' organisation association
                if (associatedOrg != null)
                {
                    _usersGateway.RemoveUserOrganisationAssociation(userId);
                    associatedOrg = null;
                }
            }

            // refresh the user domain object after above changes
            userDomain = _usersGateway.GetUserById(userDomain.Id);

            return(userDomain.ToResponse());
        }