コード例 #1
0
 public bool RemoveFromRole(string roleName)
 {
     if (SecurityData.IsUserInRole(this.UserName, roleName))
     {
         SecurityData.RemoveUserFromRole(this.UserName, roleName);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
 public bool AddToRole(string roleName)
 {
     if (!SecurityData.IsUserInRole(this.UserName, roleName))
     {
         SecurityData.AddUserToRole(this.UserName, roleName);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!SecurityData.IsAuthenticated)
            {
                return(false);
            }

            if (SecurityData.GetIsAdminFromCache())
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public void ImportStuff()
        {
            this.HasLoaded = false;
            this.Site = ContentImportExportUtils.GetSerializedSiteExport(this.ImportID);

            SiteData.CurrentSite = null;

            SiteData site = SiteData.CurrentSite;

            this.Message = String.Empty;
            string sMsg = String.Empty;

            if (this.ImportSite || this.ImportPages || this.ImportPosts) {
                List<string> tags = site.GetTagList().Select(x => x.TagSlug.ToLower()).ToList();
                List<string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLower()).ToList();

                this.Site.TheTags.RemoveAll(x => tags.Contains(x.TagSlug.ToLower()));
                this.Site.TheCategories.RemoveAll(x => cats.Contains(x.CategorySlug.ToLower()));

                sMsg += "<li>Imported Tags and Categories</li>";

                List<ContentTag> lstTag = (from l in this.Site.TheTags.Distinct()
                                           select new ContentTag {
                                               ContentTagID = Guid.NewGuid(),
                                               SiteID = site.SiteID,
                                               IsPublic = l.IsPublic,
                                               TagSlug = l.TagSlug,
                                               TagText = l.TagText
                                           }).ToList();

                List<ContentCategory> lstCat = (from l in this.Site.TheCategories.Distinct()
                                                select new ContentCategory {
                                                    ContentCategoryID = Guid.NewGuid(),
                                                    SiteID = site.SiteID,
                                                    IsPublic = l.IsPublic,
                                                    CategorySlug = l.CategorySlug,
                                                    CategoryText = l.CategoryText
                                                }).ToList();

                foreach (var v in lstTag) {
                    v.Save();
                }
                foreach (var v in lstCat) {
                    v.Save();
                }
            }
            SetMsg(sMsg);

            if (this.ImportSnippets) {
                List<string> snippets = site.GetContentSnippetList().Select(x => x.ContentSnippetSlug.ToLower()).ToList();

                this.Site.TheSnippets.RemoveAll(x => snippets.Contains(x.ContentSnippetSlug.ToLower()));

                sMsg += "<li>Imported Content Snippets</li>";

                List<ContentSnippet> lstSnip = (from l in this.Site.TheSnippets.Distinct()
                                                select new ContentSnippet {
                                                    SiteID = site.SiteID,
                                                    Root_ContentSnippetID = Guid.NewGuid(),
                                                    ContentSnippetID = Guid.NewGuid(),
                                                    CreateUserId = SecurityData.CurrentUserGuid,
                                                    CreateDate = site.Now,
                                                    EditUserId = SecurityData.CurrentUserGuid,
                                                    EditDate = site.Now,
                                                    RetireDate = l.RetireDate,
                                                    GoLiveDate = l.GoLiveDate,
                                                    ContentSnippetActive = l.ContentSnippetActive,
                                                    ContentBody = l.ContentBody,
                                                    ContentSnippetSlug = l.ContentSnippetSlug,
                                                    ContentSnippetName = l.ContentSnippetName
                                                }).ToList();

                foreach (var v in lstSnip) {
                    v.Save();
                }
            }
            SetMsg(sMsg);

            if (this.ImportSite) {
                sMsg += "<li>Updated Site Name</li>";
                site.SiteName = this.Site.TheSite.SiteName;
                site.SiteTagline = this.Site.TheSite.SiteTagline;
                site.BlockIndex = this.Site.TheSite.BlockIndex;
                site.Save();
            }
            SetMsg(sMsg);

            if (!this.MapUsers) {
                this.Site.TheUsers = new List<SiteExportUser>();
            }

            //iterate author collection and find if in the system
            foreach (SiteExportUser seu in this.Site.TheUsers) {
                SecurityData sd = new SecurityData();

                ExtendedUserData usr = null;
                seu.ImportUserID = Guid.Empty;

                //attempt to find the user in the userbase
                usr = ExtendedUserData.FindByEmail(seu.Email);
                if (usr != null) {
                    seu.ImportUserID = usr.UserId;
                } else {
                    usr = ExtendedUserData.FindByUsername(seu.Login);
                    if (usr != null) {
                        seu.ImportUserID = usr.UserId;
                    }
                }

                if (this.CreateUsers) {
                    if (seu.ImportUserID == Guid.Empty) {
                        ApplicationUser user = new ApplicationUser { UserName = seu.Login, Email = seu.Email };
                        var result = sd.CreateApplicationUser(user, out usr);
                        if (result.Succeeded) {
                            usr = ExtendedUserData.FindByUsername(seu.Login);
                        }
                        seu.ImportUserID = usr.UserId;
                    }

                    if (seu.ImportUserID != Guid.Empty) {
                        ExtendedUserData ud = new ExtendedUserData(seu.ImportUserID);
                        if (!String.IsNullOrEmpty(seu.FirstName) || !String.IsNullOrEmpty(seu.LastName)) {
                            ud.FirstName = seu.FirstName;
                            ud.LastName = seu.LastName;
                            ud.Save();
                        }
                    }
                }
            }

            if (this.ImportPages) {
                sMsg += "<li>Imported Pages</li>";
                this.Content = site.GetFullSiteFileList();

                int iOrder = 0;

                SiteNav navHome = GetHomePage(site);

                if (navHome != null) {
                    iOrder = 2;
                }

                foreach (var impCP in (from c in this.Site.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                       orderby c.ThePage.NavOrder, c.ThePage.NavMenuText
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.ContentType = ContentPageType.PageType.ContentEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = this.Site.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = this.Site.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = this.Site.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = iOrder;
                    cp.TemplateFile = this.PageTemplate;

                    ContentPageExport parent = (from c in this.Site.ThePages
                                                where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                                  && c.ThePage.FileName.ToLower() == impCP.ParentFileName.ToLower()
                                                select c).FirstOrDefault();

                    BasicContentData navParent = null;
                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

                    if (parent != null) {
                        cp.Parent_ContentID = parent.NewRootContentID;
                        navParent = GetFileInfoFromList(site, parent.ThePage.FileName);
                    }

                    //if URL exists already, make this become a new version in the current series
                    if (navData != null) {
                        cp.Root_ContentID = navData.Root_ContentID;

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;

                        if (navData.NavOrder == 0) {
                            cp.NavOrder = 0;
                        }
                    }
                    //preserve homepage
                    if (navHome != null && navHome.FileName.ToLower() == cp.FileName.ToLower()) {
                        cp.NavOrder = 0;
                    }
                    //if the file url in the upload has an existing ID, use that, not the ID from the queue
                    if (navParent != null) {
                        cp.Parent_ContentID = navParent.Root_ContentID;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();

                    iOrder++;
                }
            }
            SetMsg(sMsg);

            if (this.ImportPosts) {
                sMsg += "<li>Imported Posts</li>";
                this.Content = site.GetFullSiteFileList();

                List<ContentTag> lstTags = site.GetTagList();
                List<ContentCategory> lstCategories = site.GetCategoryList();

                foreach (var impCP in (from c in this.Site.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.BlogEntry
                                       orderby c.ThePage.CreateDate
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.Parent_ContentID = null;
                    cp.ContentType = ContentPageType.PageType.BlogEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = this.Site.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = this.Site.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = this.Site.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = SiteData.BlogSortOrderNumber;
                    cp.TemplateFile = this.PostTemplate;

                    cp.ContentCategories = (from l in lstCategories
                                            join o in impCP.ThePage.ContentCategories on l.CategorySlug.ToLower() equals o.CategorySlug.ToLower()
                                            select l).Distinct().ToList();

                    cp.ContentTags = (from l in lstTags
                                      join o in impCP.ThePage.ContentTags on l.TagSlug.ToLower() equals o.TagSlug.ToLower()
                                      select l).Distinct().ToList();

                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

                    //if URL exists already, make this become a new version in the current series
                    if (navData != null) {
                        cp.Root_ContentID = navData.Root_ContentID;

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();
                }

                using (ContentPageHelper cph = new ContentPageHelper()) {
                    //cph.BulkBlogFileNameUpdateFromDate(site.SiteID);
                    cph.ResolveDuplicateBlogURLs(site.SiteID);
                    cph.FixBlogNavOrder(site.SiteID);
                }
            }
            SetMsg(sMsg);

            if (this.ImportComments) {
                sMsg += "<li>Imported Comments</li>";
                this.Content = site.GetFullSiteFileList();

                foreach (var impCP in (from c in this.Site.TheComments
                                       orderby c.TheComment.CreateDate
                                       select c).ToList()) {
                    int iCommentCount = -1;
                    PostComment pc = impCP.TheComment;
                    BasicContentData navData = GetFileInfoFromList(site, pc.FileName);
                    if (navData != null) {
                        pc.Root_ContentID = navData.Root_ContentID;
                        pc.ContentCommentID = Guid.NewGuid();

                        iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP, pc.PostCommentText);
                        if (iCommentCount < 1) {
                            iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP);
                        }

                        if (iCommentCount < 1) {
                            pc.Save();
                        }
                    }
                }
            }

            SetMsg(sMsg);
        }
コード例 #5
0
		public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model) {
			if (ModelState.IsValid) {
				var user = await securityHelper.UserManager.FindByEmailAsync(model.Email);
				if (user == null) {
					// Don't reveal that the user does not exist or is not confirmed
					return View("ForgotPasswordConfirmation");
				} else {
					SecurityData sd = new SecurityData();
					sd.ResetPassword(model.Email);
					return RedirectToAction("ForgotPasswordConfirmation");
				}
			}

			Helper.HandleErrorDict(ModelState);
			// If we got this far, something failed, redisplay form
			return View(model);
		}
コード例 #6
0
		public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model) {
			if (!ModelState.IsValid) {
				Helper.HandleErrorDict(ModelState);

				return View(model);
			}

			//var user = await UserManager.FindByNameAsync(model.Email);
			var user = await securityHelper.UserManager.FindByEmailAsync(model.Email);
			if (user == null) {
				// Don't reveal that the user does not exist
				return RedirectToAction("ResetPasswordConfirmation");
			}
			//var result = await manage.UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);
			SecurityData sd = new SecurityData();
			var result = sd.ResetPassword(user, model.Code, model.Password);
			if (result.Succeeded) {
				return RedirectToAction("ResetPasswordConfirmation");
			}
			AddErrors(result);

			Helper.HandleErrorDict(ModelState);
			return View();
		}
コード例 #7
0
		public ActionResult CreateFirstAdmin(RegisterViewModel model) {
			RedirectIfUsersExist();

			if (ModelState.IsValid) {
				SignOut();

				SecurityData sd = new SecurityData();
				ApplicationUser user = new ApplicationUser { UserName = model.UserName, Email = model.Email };

				ExtendedUserData exUser = null;
				var result = sd.CreateApplicationUser(user, model.Password, out exUser);

				if (result.Succeeded) {
					SecurityData.AddUserToRole(model.UserName, SecurityData.CMSGroup_Admins);
					SecurityData.AddUserToRole(model.UserName, SecurityData.CMSGroup_Users);

					return RedirectToAction("Index");
				}

				AddErrors(result);
			}

			Helper.HandleErrorDict(ModelState);
			return View(model);
		}
コード例 #8
0
		public ActionResult UserAdd(RegisterViewModel model) {
			if (ModelState.IsValid) {
				SecurityData sd = new SecurityData();
				ApplicationUser user = new ApplicationUser { UserName = model.UserName, Email = model.Email };

				ExtendedUserData exUser = null;
				var result = sd.CreateApplicationUser(user, model.Password, out exUser);

				if (result == IdentityResult.Success && exUser != null) {
					result = securityHelper.UserManager.SetLockoutEnabled(exUser.Id, true);

					return RedirectToAction("UserEdit", new { @id = exUser.UserId });
				}

				AddErrors(result);
			}

			Helper.HandleErrorDict(ModelState);
			return View(model);
		}
コード例 #9
0
        public void ImportStuff()
        {
            this.HasLoaded = false;
            this.Site = ContentImportExportUtils.GetSerializedWPExport(this.ImportID);

            SiteData.CurrentSite = null;

            SiteData site = SiteData.CurrentSite;

            this.Message = String.Empty;
            string sMsg = String.Empty;

            if (this.ImportSite || this.ImportPages || this.ImportPosts) {
                List<string> tags = site.GetTagList().Select(x => x.TagSlug.ToLowerInvariant()).ToList();
                List<string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLowerInvariant()).ToList();

                this.Site.Tags.RemoveAll(x => tags.Contains(x.InfoKey.ToLowerInvariant()));
                this.Site.Categories.RemoveAll(x => cats.Contains(x.InfoKey.ToLowerInvariant()));

                sMsg += "<li>Imported Tags and Categories</li>";

                List<ContentTag> lstTag = (from l in this.Site.Tags.Distinct()
                                           select new ContentTag {
                                               ContentTagID = Guid.NewGuid(),
                                               IsPublic = true,
                                               SiteID = site.SiteID,
                                               TagSlug = l.InfoKey,
                                               TagText = l.InfoLabel
                                           }).Distinct().ToList();

                List<ContentCategory> lstCat = (from l in this.Site.Categories.Distinct()
                                                select new ContentCategory {
                                                    ContentCategoryID = Guid.NewGuid(),
                                                    IsPublic = true,
                                                    SiteID = site.SiteID,
                                                    CategorySlug = l.InfoKey,
                                                    CategoryText = l.InfoLabel
                                                }).Distinct().ToList();

                foreach (var v in lstTag) {
                    v.Save();
                }
                foreach (var v in lstCat) {
                    v.Save();
                }
            }
            SetMsg(sMsg);

            if (this.ImportSite) {
                sMsg += "<li>Updated Site Name</li>";
                site.SiteName = this.Site.SiteTitle;
                site.SiteTagline = this.Site.SiteDescription;
                site.Save();
            }
            SetMsg(sMsg);

            if (!this.MapUsers) {
                this.Site.Authors = new List<WordPressUser>();
            }

            //iterate author collection and find if in the system
            foreach (WordPressUser wpu in this.Site.Authors) {
                SecurityData sd = new SecurityData();

                ExtendedUserData usr = null;
                wpu.ImportUserID = Guid.Empty;

                //attempt to find the user in the userbase
                usr = ExtendedUserData.FindByEmail(wpu.Email);
                if (usr != null && usr.UserId != Guid.Empty) {
                    wpu.ImportUserID = usr.UserId;
                } else {
                    usr = ExtendedUserData.FindByUsername(wpu.Login);
                    if (usr != null && usr.UserId != Guid.Empty) {
                        wpu.ImportUserID = usr.UserId;
                    }
                }

                if (this.CreateUsers) {
                    if (wpu.ImportUserID == Guid.Empty) {
                        ApplicationUser user = new ApplicationUser { UserName = wpu.Login, Email = wpu.Email };
                        var result = sd.CreateApplicationUser(user, out usr);
                        if (result.Succeeded) {
                            usr = ExtendedUserData.FindByUsername(wpu.Login);
                        } else {
                            throw new Exception(String.Format("Could not create user: {0} ({1}) \r\n{2}", wpu.Login, wpu.Email, String.Join("\r\n", result.Errors)));
                        }
                        wpu.ImportUserID = usr.UserId;
                    }

                    if (wpu.ImportUserID != Guid.Empty) {
                        ExtendedUserData ud = new ExtendedUserData(wpu.ImportUserID);
                        if (!String.IsNullOrEmpty(wpu.FirstName) || !String.IsNullOrEmpty(wpu.LastName)) {
                            ud.FirstName = wpu.FirstName;
                            ud.LastName = wpu.LastName;
                            ud.Save();
                        }
                    }
                }
            }

            this.Site.Comments.ForEach(r => r.ImportRootID = Guid.Empty);

            using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                if (this.ImportPages) {
                    sMsg += "<li>Imported Pages</li>";

                    int iOrder = 0;
                    SiteNav navHome = navHelper.FindHome(site.SiteID, false);
                    if (navHome != null) {
                        iOrder = 2;
                    }

                    foreach (var wpp in (from c in this.Site.Content
                                         where c.PostType == WordPressPost.WPPostType.Page
                                         orderby c.PostOrder, c.PostTitle
                                         select c).ToList()) {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(this.Site, wpp, site);
                        cp.SiteID = site.SiteID;
                        cp.ContentType = ContentPageType.PageType.ContentEntry;
                        cp.EditDate = SiteData.CurrentSite.Now;
                        cp.NavOrder = iOrder;
                        cp.TemplateFile = this.PageTemplate;

                        WordPressPost parent = (from c in this.Site.Content
                                                where c.PostType == WordPressPost.WPPostType.Page
                                                  && c.PostID == wpp.ParentPostID
                                                select c).FirstOrDefault();

                        SiteNav navParent = null;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant());
                        if (parent != null) {
                            navParent = navHelper.GetLatestVersion(site.SiteID, false, parent.ImportFileName.ToLowerInvariant());
                        }

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null) {
                            cp.Root_ContentID = navData.Root_ContentID;
                            if (navData.NavOrder == 0) {
                                cp.NavOrder = 0;
                            }
                        }

                        if (navParent != null) {
                            cp.Parent_ContentID = navParent.Root_ContentID;
                        } else {
                            if (parent != null) {
                                cp.Parent_ContentID = parent.ImportRootID;
                            }
                        }
                        //preserve homepage
                        if (navHome != null && navHome.FileName.ToLowerInvariant() == cp.FileName.ToLowerInvariant()) {
                            cp.NavOrder = 0;
                        }

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null) {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate = navData.RetireDate;
                            cp.GoLiveDate = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        this.Site.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);

                        iOrder++;
                    }
                }

                if (this.ImportPosts) {
                    sMsg += "<li>Imported Posts</li>";

                    foreach (var wpp in (from c in this.Site.Content
                                         where c.PostType == WordPressPost.WPPostType.BlogPost
                                         orderby c.PostOrder
                                         select c).ToList()) {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(this.Site, wpp, site);
                        cp.SiteID = site.SiteID;
                        cp.Parent_ContentID = null;
                        cp.ContentType = ContentPageType.PageType.BlogEntry;
                        cp.EditDate = SiteData.CurrentSite.Now;
                        cp.NavOrder = SiteData.BlogSortOrderNumber;
                        cp.TemplateFile = this.PostTemplate;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant());

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null) {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate = navData.RetireDate;
                            cp.GoLiveDate = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        this.Site.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);
                    }

                    using (ContentPageHelper cph = new ContentPageHelper()) {
                        //cph.BulkBlogFileNameUpdateFromDate(site.SiteID);
                        cph.ResolveDuplicateBlogURLs(site.SiteID);
                        cph.FixBlogNavOrder(site.SiteID);
                    }
                }
            }
            SetMsg(sMsg);

            this.Site.Comments.RemoveAll(r => r.ImportRootID == Guid.Empty);

            if (this.Site.Comments.Any()) {
                sMsg += "<li>Imported Comments</li>";
            }

            foreach (WordPressComment wpc in this.Site.Comments) {
                int iCommentCount = -1;

                iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP, wpc.CommentContent);
                if (iCommentCount < 1) {
                    iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP);
                }

                if (iCommentCount < 1) {
                    PostComment pc = new PostComment();
                    pc.ContentCommentID = Guid.NewGuid();
                    pc.Root_ContentID = wpc.ImportRootID;
                    pc.CreateDate = site.ConvertUTCToSiteTime(wpc.CommentDateUTC);
                    pc.IsApproved = false;
                    pc.IsSpam = false;

                    pc.CommenterIP = wpc.AuthorIP;
                    pc.CommenterName = wpc.Author;
                    pc.CommenterEmail = wpc.AuthorEmail;
                    pc.PostCommentText = wpc.CommentContent;
                    pc.CommenterURL = wpc.AuthorURL;

                    if (wpc.Approved == "1") {
                        pc.IsApproved = true;
                    }
                    if (wpc.Approved.ToLowerInvariant() == "trash") {
                        pc.IsSpam = true;
                    }
                    if (wpc.Type.ToLowerInvariant() == "trackback" || wpc.Type.ToLowerInvariant() == "pingback") {
                        pc.CommenterEmail = wpc.Type;
                    }

                    pc.Save();
                }
            }
            SetMsg(sMsg);
        }
コード例 #10
0
 public IdentityResult CreateApplicationUser(ApplicationUser user, out ExtendedUserData newusr)
 {
     return(AttemptCreateApplicationUser(user, SecurityData.GenerateSimplePassword(), out newusr));
 }
コード例 #11
0
        public static ContentPage CreateWPContentPage(WordPressSite wps, WordPressPost c, SiteData site)
        {
            ContentPage cont = null;

            ContentPageType.PageType contType = ContentPageType.PageType.Unknown;
            switch (c.PostType)
            {
            case WordPressPost.WPPostType.BlogPost:
                contType = ContentPageType.PageType.BlogEntry;
                break;

            case WordPressPost.WPPostType.Page:
                contType = ContentPageType.PageType.ContentEntry;
                break;
            }

            if (c != null)
            {
                cont           = new ContentPage(site.SiteID, contType);
                cont.ContentID = Guid.NewGuid();

                cont.CreateUserId = SecurityData.CurrentUserGuid;
                cont.EditUserId   = SecurityData.CurrentUserGuid;

                if (!String.IsNullOrEmpty(c.PostAuthor))
                {
                    WordPressUser wpu = wps.Authors.Where(x => x.Login.ToLower() == c.PostAuthor.ToLower()).FirstOrDefault();

                    if (wpu != null && wpu.ImportUserID != Guid.Empty)
                    {
                        ApplicationUser usr = SecurityData.GetUserByID(wpu.ImportUserID.ToString());
                        if (usr != null)
                        {
                            cont.CreateUserId = wpu.ImportUserID;
                            cont.EditUserId   = wpu.ImportUserID;
                        }
                    }
                }

                cont.Root_ContentID   = c.ImportRootID;
                cont.FileName         = c.ImportFileName.Replace("//", "/");
                cont.PageSlug         = null;
                cont.NavOrder         = c.PostOrder;
                cont.Parent_ContentID = null;

                cont.CreateDate  = site.ConvertUTCToSiteTime(c.PostDateUTC);
                cont.PageActive  = c.IsPublished;
                cont.ContentType = ContentPageType.PageType.Unknown;

                if (c.PostType == WordPressPost.WPPostType.BlogPost)
                {
                    cont.ContentType      = ContentPageType.PageType.BlogEntry;
                    cont.PageSlug         = c.ImportFileSlug.Replace("//", "/");
                    cont.NavOrder         = SiteData.BlogSortOrderNumber;
                    cont.Parent_ContentID = null;
                }
                if (c.PostType == WordPressPost.WPPostType.Page)
                {
                    cont.ContentType = ContentPageType.PageType.ContentEntry;
                }

                if (cont.ContentType == ContentPageType.PageType.ContentEntry)
                {
                    cont.ShowInSiteMap = true;
                    cont.ShowInSiteNav = true;
                }
                else
                {
                    cont.ShowInSiteMap = false;
                    cont.ShowInSiteNav = false;
                }

                cont.IsLatestVersion = true;

                cont.IsLatestVersion = true;
                cont.TitleBar        = c.PostTitle;
                cont.NavMenuText     = c.PostTitle;
                cont.PageHead        = c.PostTitle;
                cont.PageText        = c.PostContent;
                cont.LeftPageText    = String.Empty;
                cont.RightPageText   = String.Empty;

                cont.MetaDescription = String.Empty;
                cont.MetaKeyword     = String.Empty;

                cont.ContentCategories = new List <ContentCategory>();
                cont.ContentTags       = new List <ContentTag>();

                List <ContentTag>      lstTags       = site.GetTagList();
                List <ContentCategory> lstCategories = site.GetCategoryList();

                cont.ContentCategories = (from l in lstCategories
                                          join o in c.Categories on l.CategorySlug.ToLower() equals o.ToLower()
                                          select l).Distinct().ToList();

                cont.ContentTags = (from l in lstTags
                                    join o in c.Tags on l.TagSlug.ToLower() equals o.ToLower()
                                    select l).Distinct().ToList();
            }

            return(cont);
        }
コード例 #12
0
 public bool RemoveFromRole(string roleName)
 {
     return(SecurityData.RemoveUserFromRole(this.UserName, roleName));
 }
コード例 #13
0
 public bool AddToRole(string roleName)
 {
     return(SecurityData.AddUserToRole(this.UserName, roleName));
 }
コード例 #14
0
		public async Task<ActionResult> ResetPassword(ResetPasswordInfo model) {
			model.ReconstructSettings();
			this.ViewData[ResetPasswordInfo.Key] = model;

			LoadPage(model.Settings.Uri);

			var settings = model.Settings;

			if (settings.UseValidateHuman) {
				bool IsValidated = model.ValidateHuman.ValidateValue(model.ValidationValue);
				if (!IsValidated) {
					ModelState.AddModelError("ValidationValue", model.ValidateHuman.AltValidationFailText);
					model.ValidationValue = String.Empty;
				}
			}

			if (String.IsNullOrEmpty(settings.UserCode)) {
				ModelState.AddModelError(String.Empty, "Reset code not provided.");
			}

			if (ModelState.IsValid) {
				string confirmView = settings.PostPartialName;
				if (!String.IsNullOrEmpty(settings.PostPartialName)) {
					confirmView = settings.PostPartialConfirmation;
				}

				var user = await securityHelper.UserManager.FindByEmailAsync(model.Email);
				if (user == null) {
					return PartialView(confirmView, model);
				} else {
					SecurityData sd = new SecurityData();
					var result = sd.ResetPassword(user, settings.UserCode, model.Password);
					model.CreationResult = result;

					if (result.Succeeded) {
						return PartialView(confirmView, model);
					}

					AddErrors(result);
				}
			}

			Helper.HandleErrorDict(ModelState);

			return PartialView(settings.PostPartialName, model);
		}
コード例 #15
0
		public async Task<ActionResult> ForgotPassword(ForgotPasswordInfo model) {
			model.ReconstructSettings();
			this.ViewData[ForgotPasswordInfo.Key] = model;

			LoadPage(model.Settings.Uri);

			var settings = model.Settings;

			if (settings.UseValidateHuman) {
				bool IsValidated = model.ValidateHuman.ValidateValue(model.ValidationValue);
				if (!IsValidated) {
					ModelState.AddModelError("ValidationValue", model.ValidateHuman.AltValidationFailText);
					model.ValidationValue = String.Empty;
				}
			}

			string confirmView = settings.PostPartialName;
			if (!String.IsNullOrEmpty(settings.PostPartialName)) {
				confirmView = settings.PostPartialConfirmation;
			}

			string confirmUri = settings.Uri;
			if (!String.IsNullOrEmpty(settings.ConfirmUri)) {
				confirmUri = settings.ConfirmUri;
			}

			if (ModelState.IsValid) {
				var user = await securityHelper.UserManager.FindByEmailAsync(model.Email);
				if (user != null) {
					SecurityData sd = new SecurityData();
					sd.ResetPassword(confirmUri, model.Email);
				}

				return PartialView(confirmView, model);
			}

			Helper.HandleErrorDict(ModelState);

			return PartialView(settings.PostPartialName, model);
		}