public async Task <ProfileModel?> BuildForCurrentMemberAsync()
    {
        IMemberManager?memberManager =
            _httpContextAccessor.HttpContext?.RequestServices.GetRequiredService <IMemberManager>();

        if (memberManager == null)
        {
            return(null);
        }

        MemberIdentityUser?member = _httpContextAccessor.HttpContext is null
            ? null
            : await memberManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

        if (member == null)
        {
            return(null);
        }

        var model = new ProfileModel
        {
            Name                    = member.Name,
            Email                   = member.Email,
            UserName                = member.UserName,
            Comments                = member.Comments,
            IsApproved              = member.IsApproved,
            IsLockedOut             = member.IsLockedOut,
            LastLockoutDate         = member.LastLockoutDateUtc?.ToLocalTime(),
            CreatedDate             = member.CreatedDateUtc.ToLocalTime(),
            LastLoginDate           = member.LastLoginDateUtc?.ToLocalTime(),
            LastPasswordChangedDate = member.LastPasswordChangeDateUtc?.ToLocalTime(),
            RedirectUrl             = _redirectUrl,
            Key = member.Key,
        };

        IMemberType?memberType = member.MemberTypeAlias is null ? null : MemberTypeService.Get(member.MemberTypeAlias);

        if (memberType == null)
        {
            throw new InvalidOperationException($"Could not find a member type with alias: {member.MemberTypeAlias}.");
        }

        // TODO: This wouldn't be required if we support exposing custom member properties on the MemberIdentityUser at the ASP.NET Identity level.
        IMember?persistedMember = _memberService.GetByKey(member.Key);

        if (persistedMember == null)
        {
            // should never happen
            throw new InvalidOperationException($"Could not find a member with key: {member.Key}.");
        }

        if (_lookupProperties)
        {
            model.MemberProperties = GetMemberPropertiesViewModel(memberType, persistedMember);
        }

        return(model);
    }
Example #2
0
        public RegisterModel Build()
        {
            var         providedOrDefaultMemberTypeAlias = _memberTypeAlias ?? Core.Constants.Conventions.MemberTypes.DefaultAlias;
            IMemberType memberType = MemberTypeService.Get(providedOrDefaultMemberTypeAlias);

            if (memberType == null)
            {
                throw new InvalidOperationException($"Could not find a member type with alias: {providedOrDefaultMemberTypeAlias}.");
            }

            var model = new RegisterModel
            {
                MemberTypeAlias  = providedOrDefaultMemberTypeAlias,
                UsernameIsEmail  = _usernameIsEmail,
                MemberProperties = _lookupProperties ? GetMemberPropertiesViewModel(memberType) : Enumerable.Empty <MemberPropertyModel>().ToList()
            };

            return(model);
        }
 public Tbl_MemberType Get(int id)
 {
     return(_memberTypeService.Get(id));
 }
Example #4
0
        /// <summary>
        ///     Returns the available composite content types for a given content type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="filterContentTypes">
        ///     This is normally an empty list but if additional content type aliases are passed in, any content types containing
        ///     those aliases will be filtered out
        ///     along with any content types that have matching property types that are included in the filtered content types
        /// </param>
        /// <param name="filterPropertyTypes">
        ///     This is normally an empty list but if additional property type aliases are passed in, any content types that have
        ///     these aliases will be filtered out.
        ///     This is required because in the case of creating/modifying a content type because new property types being added to
        ///     it are not yet persisted so cannot
        ///     be looked up via the db, they need to be passed in.
        /// </param>
        /// <param name="contentTypeId"></param>
        /// <param name="isElement">Whether the composite content types should be applicable for an element type</param>
        /// <returns></returns>
        protected ActionResult <IEnumerable <Tuple <EntityBasic?, bool> > > PerformGetAvailableCompositeContentTypes(
            int contentTypeId,
            UmbracoObjectTypes type,
            string[]?filterContentTypes,
            string[]?filterPropertyTypes,
            bool isElement)
        {
            IContentTypeComposition?source = null;

            //below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic

            IContentTypeComposition[] allContentTypes;

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                if (contentTypeId > 0)
                {
                    source = ContentTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = ContentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            case UmbracoObjectTypes.MediaType:
                if (contentTypeId > 0)
                {
                    source = MediaTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = MediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            case UmbracoObjectTypes.MemberType:
                if (contentTypeId > 0)
                {
                    source = MemberTypeService.Get(contentTypeId);
                    if (source == null)
                    {
                        return(NotFound());
                    }
                }

                allContentTypes = MemberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray();
                break;

            default:
                throw new ArgumentOutOfRangeException("The entity type was not a content type");
            }

            ContentTypeAvailableCompositionsResults availableCompositions =
                ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes, filterContentTypes,
                                                                     filterPropertyTypes, isElement);


            IContentTypeComposition[] currCompositions =
                source == null ? new IContentTypeComposition[] { } : source.ContentTypeComposition.ToArray();
            var compAliases = currCompositions.Select(x => x.Alias).ToArray();
            IEnumerable <string> ancestors = availableCompositions.Ancestors.Select(x => x.Alias);

            return(availableCompositions.Results
                   .Select(x =>
                           new Tuple <EntityBasic?, bool>(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>(x.Composition),
                                                          x.Allowed))
                   .Select(x =>
            {
                //we need to ensure that the item is enabled if it is already selected
                // but do not allow it if it is any of the ancestors
                if (compAliases.Contains(x.Item1?.Alias) && ancestors.Contains(x.Item1?.Alias) == false)
                {
                    //re-set x to be allowed (NOTE: I didn't know you could set an enumerable item in a lambda!)
                    x = new Tuple <EntityBasic?, bool>(x.Item1, true);
                }

                //translate the name
                if (x.Item1 is not null)
                {
                    x.Item1.Name = TranslateItem(x.Item1.Name);
                }

                IContentTypeComposition?contentType = allContentTypes.FirstOrDefault(c => c.Key == x.Item1?.Key);
                EntityContainer[] containers = GetEntityContainers(contentType, type).ToArray();
                var containerPath =
                    $"/{(containers.Any() ? $"{string.Join("/", containers.Select(c => c.Name))}/" : null)}";
                if (x.Item1 is not null)
                {
                    x.Item1.AdditionalData["containerPath"] = containerPath;
                }

                return x;
            })
                   .ToList());
        }
Example #5
0
        /// <summary>
        ///     Returns a list of content types where a particular composition content type is used
        /// </summary>
        /// <param name="type">Type of content Type, eg documentType or mediaType</param>
        /// <param name="contentTypeId">Id of composition content type</param>
        /// <returns></returns>
        protected ActionResult <IEnumerable <EntityBasic> > PerformGetWhereCompositionIsUsedInContentTypes(
            int contentTypeId, UmbracoObjectTypes type)
        {
            var id = 0;

            if (contentTypeId > 0)
            {
                IContentTypeComposition?source;

                switch (type)
                {
                case UmbracoObjectTypes.DocumentType:
                    source = ContentTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MediaType:
                    source = MediaTypeService.Get(contentTypeId);
                    break;

                case UmbracoObjectTypes.MemberType:
                    source = MemberTypeService.Get(contentTypeId);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
                }

                if (source == null)
                {
                    return(NotFound());
                }

                id = source.Id;
            }

            IEnumerable <IContentTypeComposition> composedOf;

            switch (type)
            {
            case UmbracoObjectTypes.DocumentType:
                composedOf = ContentTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MediaType:
                composedOf = MediaTypeService.GetComposedOf(id);
                break;

            case UmbracoObjectTypes.MemberType:
                composedOf = MemberTypeService.GetComposedOf(id);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            EntityBasic TranslateName(EntityBasic e)
            {
                e.Name = TranslateItem(e.Name);
                return(e);
            }

            return(composedOf
                   .Select(UmbracoMapper.Map <IContentTypeComposition, EntityBasic>)
                   .WhereNotNull()
                   .Select(TranslateName)
                   .ToList());
        }