public User Update(Guid id, string name, string email, string preferredCulture)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("Id must have a value");
            }

            var user = this.Get(id);

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

            this.CheckEmailAvailable(email, id);
            user.Name             = name;
            user.Email            = email;
            user.PreferredCulture = preferredCulture;

            var args = new Dictionary <string, object>();

            args.Add("Id", user.Id);
            args.Add("UserName", user.Name);
            args.Add("UserEmail", user.Email);
            StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("UserUpdateEvent", args));

            return(user);
        }
        public Group Create(string name, bool usePermissions)
        {
            if (this.Exists(name, null))
            {
                var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name));
                Logger.Log(ex.Message, ex, LogLevel.Fatal);
                throw ex;
            }

            var currentUserId = StrixPlatform.User.Id;

            if (currentUserId == null)
            {
                throw new StrixMembershipException("No active user");
            }

            var group = new Group(Guid.NewGuid(), name);

            group.UsePermissions = usePermissions;
            group = this._dataSource.Save(group);

            if (group == null)
            {
                Logger.Log(string.Format("An error occurred while creating group {0}", group.Name), LogLevel.Error);
            }
            else
            {
                var args = new Dictionary <string, object>();
                args.Add("Id", group.Id);
                args.Add("GroupName", group.Name);
                StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("GroupCreateEvent", args));
            }

            return(group);
        }
        public Group Update(Guid id, string name, bool usePermissions)
        {
            if (this.Exists(name, id))
            {
                var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name));
                Logger.Log(ex.Message, ex, LogLevel.Fatal);
                throw ex;
            }

            var currentUserId = StrixPlatform.User.Id;

            if (currentUserId == null)
            {
                throw new StrixMembershipException("No active user");
            }

            var group = this.Get(id);

            if (group != null)
            {
                if (group.Name.ToLower() != name.ToLower())
                {
                    group.Name = name;
                }

                group.UsePermissions = usePermissions;

                var args = new Dictionary <string, object>();
                args.Add("Id", group.Id);
                args.Add("GroupName", group.Name);
                StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("GroupUpdateEvent", args));
            }

            return(group);
        }
Beispiel #4
0
        public virtual TModel GetCached(string url, string permissionKey = null)
        {
            TModel entity         = null;
            var    currentCulture = StrixPlatform.CurrentCultureCode;
            var    cacheKey       = string.Format(CmsConstants.CONTENTPERCULTURE, typeof(TModel).Name) + permissionKey;

            // First, try to get the content from the cache. If it is not there, retrieve it from
            // the database and add it to the cache.
            var tupleList = this._cache[cacheKey] as List <Tuple <string, string, dynamic> >;

            if (tupleList != null)
            {
                var tuple = tupleList.Where(tu => tu.Item1.ToLower() == url.ToLower() && tu.Item2 == currentCulture).FirstOrDefault();
                entity = tuple != null ? tuple.Item3 : null;
            }

            if (entity == null)
            {
                entity = this.Get(url);
                StrixPlatform.RaiseEvent <CacheEntityModelEvent <TModel> >(new CacheEntityModelEvent <TModel>(entity));

                if (tupleList == null)
                {
                    tupleList = new List <Tuple <string, string, dynamic> >();
                }

                tupleList.Add(new Tuple <string, string, dynamic>(url, currentCulture, entity));
                this._cache[cacheKey] = tupleList;
            }

            return(entity);
        }
Beispiel #5
0
        public void Initialize()
        {
            StrixPlatform.WriteStartupMessage("Check and create the application.");
            this.InitApplication();

            StrixPlatform.WriteStartupMessage("Check and create the main group.");
            this.InitMainGroup();

            StrixPlatform.WriteStartupMessage("Check and create the admin user.");
            this.InitAdminUser();

            StrixPlatform.WriteStartupMessage("Check and create the application permissions.");
            this.InitPermissions();
        }
        public User Create(string name, string email, string preferredCulture, string password, bool isApproved, bool acceptedTerms, string registrationComment)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("email");
            }

            this.CheckEmailAvailable(email);
            User user = this._dataSource.Query <User>().FirstOrDefault(u => u.Email.ToLower() == email.ToLower());

            if (user == null)
            {
                CheckPassword(password);
                var encodedPassword = this._securityManager.EncodePassword(password);

                user = new User(Guid.NewGuid(), email, name);
                user.PreferredCulture  = string.IsNullOrWhiteSpace(preferredCulture) ? StrixPlatform.CurrentCultureCode : preferredCulture;
                user.DateAcceptedTerms = acceptedTerms ? (DateTime?)DateTime.Now : null;

                var security = new UserSecurity(user.Id);
                security.Password            = encodedPassword;
                security.Approved            = isApproved || StrixMembership.Configuration.Registration.AutoApproveUsers;
                security.RegistrationComment = registrationComment;

                var session = new UserSessionStorage(user.Id);

                user     = this._dataSource.Save(user);
                security = this._dataSource.Save(security);
                session  = this._dataSource.Save(session);

                if (security == null || session == null)
                {
                    user = null;
                }
            }

            if (user != null)
            {
                var args = new Dictionary <string, object>();
                args.Add("Id", user.Id);
                args.Add("UserName", user.Name);
                args.Add("UserEmail", user.Email);
                StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("UserCreateEvent", args));
            }

            return(user);
        }
Beispiel #7
0
        public override IEnumerable List(FilterOptions filter)
        {
            if (!typeof(EntityViewModel).IsAssignableFrom(typeof(TModel)))
            {
                return(base.List(filter));
            }

            var        map     = EntityHelper.GetObjectMap(typeof(TModel));
            var        culture = StrixPlatform.CurrentCultureCode.ToLower();
            IQueryable query   = this.Manager.Query(map.ContentType).Where("Culture.ToLower().Equals(@0) AND IsCurrentVersion", culture);

            var queryEvent = new PrepareQueryEvent(query, filter);

            StrixPlatform.RaiseEvent(queryEvent);
            query = queryEvent.Query;

            return(query.Map(map.ListModelType));
        }
Beispiel #8
0
        private bool SendMail(string culture, string message, string email, Dictionary <string, string> tokens)
        {
            tokens.Add("[[SITENAME]]", StrixPlatform.Configuration.ApplicationName);
            tokens.Add("[[BASEURL]]", this.GetBaseUrl(culture));
            var templateDir = StrixMembership.Configuration.MailTemplateFolder;
            var directory   = StrixPlatform.Environment.MapPath(templateDir);
            var template    = this._fileSystemWrapper.GetHtmlTemplate(directory, "MailTemplate", culture).FirstOrDefault();
            var mail        = this._fileSystemWrapper.GetHtmlTemplate(directory, message, culture).FirstOrDefault();

            if (template == null)
            {
                Logger.Log(string.Format("No template {0} found for culture {1}", message, culture));
            }

            // Raise an event to allow the mail information to be replaced.
            var args = new Dictionary <string, object>();

            args.Add("TemplateName", message);
            args.Add("Culture", culture);
            args.Add("Template", template.Body);
            args.Add("Body", mail.Body);
            args.Add("Subject", mail.Subject);
            args.Add("Tokens", tokens);

            StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("SendMembershipMailEvent", args));

            template.Body = (string)args["Template"];
            mail.Body     = (string)args["Body"];
            mail.Subject  = (string)args["Subject"];

            mail.Body     = Tokenizer.ReplaceTokens(mail.Body, tokens);
            template.Body = template.Body.Replace("[[CONTENT]]", mail.Body);
            mail.Subject  = Tokenizer.ReplaceTokens(mail.Subject, tokens);

            var    mailSettings = Helpers.GetConfigSectionGroup <MailSettingsSectionGroup>("system.net/mailSettings");
            string from         = mailSettings.Smtp.From;

            return(this._mailer.SendMail(from, email, mail.Subject, template.Body));
        }
        public SearchResult Search(FilterOptions options)
        {
            if (options == null)
            {
                options = new FilterOptions();
            }

            var culture = StrixPlatform.CurrentCultureCode;
            var result  = new SearchResult();

            result.Locators = PageRegistration.ContentLocators;
            var typesTosearch = EntityHelper.EntityTypes.Where(e => e.Name != typeof(MailContentTemplate).FullName && e.Name != typeof(MailContent).FullName).ToList();
            var itemsToSkip   = options.PageSize == 1 ? 0 : options.PageSize * (options.Page - 1);

            // Todo: make configurable.
            var itemsToGet = options.PageSize == 0 ? 100 : options.PageSize;

            foreach (var entityType in typesTosearch)
            {
                var entryType = EntityHelper.GetEntityType(entityType.Id);
                var query     = this._source.Query(entryType).Where("Culture.Equals(@0) AND IsCurrentVersion", culture);

                var queryEvent = new PrepareQueryEvent(query, options, false);
                StrixPlatform.RaiseEvent(queryEvent);
                query = queryEvent.Query;

                if (itemsToGet > 0)
                {
                    if (entryType.Equals(typeof(Html)))
                    {
                        var htmlTypeName = typeof(Html).FullName;
                        var htmlLocators = PageRegistration.ContentLocators.Where(l => l.ContentTypeName == htmlTypeName);
                        var htmlQuery    = query.Cast <Html>().Select(h => new { Name = h.Name, Url = h.Entity.Url }).ToList().Select(h => new { Name = h.Name, Url = htmlLocators.Where(l => l.ContentUrl.ToLower() == h.Url.ToLower()).Select(l => l.PageUrl).FirstOrDefault() });
                        query = htmlQuery.GroupBy(h => h.Url).Select(h => new Html {
                            Name = h.Select(i => i.Url.ToTitleCase()).First(), Entity = new PlatformEntity {
                                Id = Guid.Empty, Url = h.Select(i => i.Url).First()
                            }
                        }).AsQueryable();
                    }

                    int addedItems = 0;
                    var entries    = query.Skip(itemsToSkip).Take(itemsToGet).Select <SearchItem>("new (Entity.Id, Name, Entity.Url)").ToList();

                    foreach (var entry in entries)
                    {
                        entry.TypeName = entryType.FullName;
                        result.Data.Add(entry);
                        addedItems++;
                    }

                    options.Total = 0;
                    itemsToGet   -= addedItems;
                }

                var queryCount = query.Count();
                itemsToSkip -= queryCount;

                if (itemsToSkip < 0)
                {
                    itemsToSkip = 0;
                }

                result.Total += queryCount;
            }

            return(result);
        }