A User entity
Inheritance: MemberProfile, IMembershipUser
コード例 #1
0
        public void Initialize()
        {
            #region Vars

            IReadonlyEntityRepositoryGroup<IContentStore> readonlyContentStoreRepository;
            IReadonlySchemaRepositoryGroup<IContentStore> readonlyContentStoreSchemaRepository;
            IEntityRepositoryGroup<IContentStore> contentStoreRepository;
            ISchemaRepositoryGroup<IContentStore> contentStoreSchemaRepository;

            IReadonlyEntityRepositoryGroup<IFileStore> readonlyFileStoreRepository;
            IReadonlySchemaRepositoryGroup<IFileStore> readonlyFileStoreSchemaRepository;
            IEntityRepositoryGroup<IFileStore> fileStoreRepository;
            ISchemaRepositoryGroup<IFileStore> fileStoreSchemaRepository;

            #endregion

            var hive = MockHiveManager.GetManager()
                .MockContentStore(out readonlyContentStoreRepository, out readonlyContentStoreSchemaRepository, out contentStoreRepository, out contentStoreSchemaRepository)
                .MockFileStore(out readonlyFileStoreRepository, out readonlyFileStoreSchemaRepository, out fileStoreRepository, out fileStoreSchemaRepository);

            //Setup file store
            var fileId = new HiveId("storage", "file-uploader", new HiveIdValue("test.jpg"));
            var file = new File
            {
                Id = fileId,
                Name = "test.jpg",
                ContentBytes = Encoding.UTF8.GetBytes("test")
            };

            readonlyFileStoreRepository
                .Get<File>(true, Arg.Any<HiveId[]>())
                .Returns(new[] { file });

            var thumbnailId = new HiveId("storage", "file-uploader", new HiveIdValue("test_100.jpg"));
            var thumbnail = new File
            {
                Id = thumbnailId,
                Name = "test_100.jpg",
                ContentBytes = Encoding.UTF8.GetBytes("test_100")
            };

            var relation = Substitute.For<IReadonlyRelation<IRelatableEntity, IRelatableEntity>>();
            relation.MetaData.Returns(new RelationMetaDataCollection(new[] { new RelationMetaDatum("size", "100") }));
            relation.Source.Returns(file);
            relation.SourceId.Returns(fileId);
            relation.Destination.Returns(thumbnail);
            relation.DestinationId.Returns(thumbnailId);

            readonlyFileStoreRepository.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType)
                .Returns(new[]{ relation });

            //Setup media store
            var mediaPickerAttributeDefType = new AttributeType { RenderTypeProvider = CorePluginConstants.FileUploadPropertyEditorId };
            var mediaPickerAttributeDef = new AttributeDefinition("rebelFile", "") { Id = FixedHiveIds.FileUploadAttributeType, AttributeType = mediaPickerAttributeDefType };
            var mediaPickerProperty = new TypedAttribute(mediaPickerAttributeDef, fileId.ToString());

            var mediaId = new HiveId("0A647849-BF5C-413B-9420-7AB4C9521505");
            var mediaEntity = new TypedEntity { Id = mediaId };
            //mediaEntity.SetupFromSchema(FixedSchemas.MediaImageSchema);
            mediaEntity.Attributes.Add(mediaPickerProperty);
            mediaEntity.Attributes["rebelFile"].Values["MediaId"] = "0A647849-BF5C-413B-9420-7AB4C9521505";

            //readonlyContentStoreRepository
            //    .Get<TypedEntity>(true, Arg.Any<HiveId[]>())
            //    .Returns(new[] { mediaEntity });

            //readonlyContentStoreRepository
            //    .SingleOrDefault<TypedEntity>(Arg.Any<Expression<Func<TypedEntity, bool>>>())
            //    .Returns(mediaEntity);

            var mediaEntityList = new List<TypedEntity> { mediaEntity };
            readonlyContentStoreRepository
                .Query()
                .Returns(mediaEntityList.AsQueryable());

            // Setup application
            var appContext = Substitute.For<IRebelApplicationContext>();
            appContext.Hive.Returns(hive);

            // Setup back office request
            _backOfficeRequestContext = Substitute.For<IBackOfficeRequestContext>();
            _backOfficeRequestContext.Application.Returns(appContext);

            var member = new Member {Id = new HiveId("0285372B-AB14-45B6-943A-8709476AB655"), Username = "******"};

            // Setup fake HttpContext (Just needed to fake current member)
            var identity = new GenericIdentity(member.Username);
            var user = new GenericPrincipal(identity, new string[0]);
            var wp = new SimpleWorkerRequest("/virtual", "c:\\inetpub\\wwwroot\\physical\\", "page.aspx", "query", new StringWriter());
            HttpContext.Current = new HttpContext(wp) {User = user};

            appContext.Security.Members.GetByUsername(member.Username).Returns(member);

            appContext.Security.PublicAccess.GetPublicAccessStatus(member.Id, mediaEntity.Id)
                .Returns(new PublicAccessStatusResult(mediaEntity.Id, true));
        }
コード例 #2
0
 /// <summary>
 /// Filters the with public access.
 /// </summary>
 /// <param name="entityIds">The entity ids.</param>
 /// <param name="member">The member.</param>
 /// <param name="publicAccessService">The public access service.</param>
 /// <returns></returns>
 public static IEnumerable<HiveId> FilterWithPublicAccess(this IEnumerable<HiveId> entityIds,
     Member member,
     IPublicAccessService publicAccessService)
 {
     return entityIds.FilterWithPublicAccess(member == null ? HiveId.Empty : member.Id, publicAccessService);
 }
コード例 #3
0
        public ActionResult RegisterForm([Bind(Prefix = "RegisterForm")]RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return CurrentRebelPage();
            }

            //  Create a member
            using (var uow = _context.Application.Hive.OpenWriter<ISecurityStore>())
            {
                var member = new Member();
                member.SetupFromSchema(model.MemberTypeAlias, uow);
                member.Name = model.Name;
                member.Username = model.Username;
                member.Email = model.Email;
                member.Password = model.Password;
                member.IsApproved = true;
                member.Groups = new[] { model.MemberGroupId };

                MembershipCreateStatus status;
                _context.Application.Security.Members.Create(member, out status);

                if (status != MembershipCreateStatus.Success)
                {
                    ModelState.AddModelError("RegisterForm.", "Error creating member: " + status.ToString());
                    return CurrentRebelPage();
                }

                if(!model.SuccessRedirectId.IsNullValueOrEmpty())
                {
                    return Redirect(_context.RoutingEngine.GetUrl(model.SuccessRedirectId));
                }

                return RedirectToCurrentRebelPage();
            }
        }