Exemple #1
0
        private void CheckForAdminUser()
        {
            var roles = CodeFirstRoleServices.GetUsersInRole(BgResources.Security_AdminRole);

            if (roles.Length == 0)
            {
                CodeFirstSecurity.CreateAccount(BgResources.Security_AdminRole, "admin", BgResources.Email_UserName, false);
                CodeFirstRoleServices.AddUsersToRoles(new string[] { "admin" }, new string[] { BgResources.Security_AdminRole, BgResources.Security_PremiumRole });
            }
        }
Exemple #2
0
 public ActionResult ArchiveList()
 {
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(PartialView("_archiveListView", BlogServices.FindAllPostsByDate(true)));
     }
     else
     {
         return(PartialView("_archiveListView", BlogServices.FindAllPostsByDate(false)));
     }
 }
Exemple #3
0
 public ActionResult Galeria()
 {
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(View(MediaServices.FindAlbumsForRole(true)));
     }
     else
     {
         return(View(MediaServices.FindAlbumsForRole(false)));
     }
 }
Exemple #4
0
 public ActionResult Index()
 {
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(View(BlogServices.HomePostsForRole(true, Int32.Parse(BgResources.Pager_HomeIndexPostsPerPage))));
     }
     else
     {
         return(View(BlogServices.HomePostsForRole(false, Int32.Parse(BgResources.Pager_HomeIndexPostsPerPage))));
     }
 }
Exemple #5
0
 /// <summary>
 /// Get stats for the stats widget
 /// </summary>
 /// <returns>Stats for show in sidebar stats widget</returns>
 public ActionResult SidebarStats()
 {
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(PartialView("SidebarStats", Mapper.Map <StatsDTO, StatsModel>(StatsServices.RetrieveSidebarStats(true))));
     }
     else
     {
         return(PartialView("SidebarStats", Mapper.Map <StatsDTO, StatsModel>(StatsServices.RetrieveSidebarStats(false))));
     }
 }
Exemple #6
0
 public ActionResult TagCloud()
 {
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(PartialView("TagCloud", BlogServices.GetModelForTagCloud(true)));
     }
     else
     {
         return(PartialView("TagCloud", BlogServices.GetModelForTagCloud(false)));
     }
 }
Exemple #7
0
        //
        // GET: /Home/GetVideoAutoCompleteSuggestions/id

        public JsonResult GetVideoAutoCompleteSuggestions(string term)
        {
            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                return(Json(MediaServices.BuildVideoAutocompleteSuggestions(term, true), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(MediaServices.BuildVideoAutocompleteSuggestions(term, false), JsonRequestBehavior.AllowGet));
            }
        }
Exemple #8
0
        public ActionResult GetPostsByTag(string id, int?page)
        {
            ViewBag.Action = "GetPostsByTag";
            ViewBag.Route  = "Default";
            ViewBag.Tag    = id;
            ViewBag.Title  = "Posts - " + id;
            var pageIndex = page ?? 0;

            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                return(View("Posts", BlogServices.FindPagedPostsByTag(true, id, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
            else
            {
                return(View("Posts", BlogServices.FindPagedPostsByTag(true, id, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
        }
Exemple #9
0
        public ActionResult GetPostsByDate(int year, int month, int?page)
        {
            ViewBag.Title  = "Posts - " + new DateTime(year, month, 1).ToString("y");
            ViewBag.Action = "GetPostsByDate";
            ViewBag.Year   = year;
            ViewBag.Month  = month;
            ViewBag.Route  = "PostByDate";
            var pageIndex = page ?? 0;

            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                return(View("Posts", BlogServices.FindPagedPostsByDate(true, year, month, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
            else
            {
                return(View("Posts", BlogServices.FindPagedPostsByDate(false, year, month, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
        }
Exemple #10
0
        public ActionResult Galleria(int id)
        {
            Album album = AlbumServices.FindEntityByIdentity(id);

            if (album == null)
            {
                return(new NotFoundMvc.NotFoundViewResult());
            }
            if ((album.IsPublic) || (CodeFirstSecurity.IsAuthenticated && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole))))
            {
                return(View("Galleria", album));
            }
            else
            {
                TempData["returnUrl"] = Request.Url.ToString();
                return(RedirectToRoute("Default", new { controller = "Account", action = "LogOn" }));
            }
        }
Exemple #11
0
        public ActionResult GetPostById(int id)
        {
            Post post = BlogServices.FindPost(id);

            if (post == null)
            {
                return(new NotFoundMvc.NotFoundViewResult());
            }
            ViewBag.MetaDescription = post.Description;
            if ((post.IsPublic) || (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.IsAuthenticated ? CodeFirstSecurity.CurrentUserName : "******", BgResources.Security_PremiumRole)))
            {
                return(View("Post", post));
            }
            else
            {
                TempData["returnUrl"] = Request.Url.ToString();
                return(RedirectToRoute("Default", new { controller = "Account", action = "LogOn" }));
            }
        }
Exemple #12
0
 /// <summary>
 /// Get latest videos published for home index
 /// </summary>
 /// <returns>List of videos</returns>
 public ActionResult LatestVideos(string tag, string category)
 {
     if (!(String.IsNullOrEmpty(tag) && String.IsNullOrEmpty(category)))
     {
         ViewBag.IsHome = false;
     }
     else
     {
         ViewBag.IsHome = true;
     }
     if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
     {
         return(PartialView(MediaServices.FindLatestVideos(6, true, tag, category)));
     }
     else
     {
         return(PartialView(MediaServices.FindLatestVideos(6, false, tag, category)));
     }
 }
Exemple #13
0
        /// <summary>
        /// Create new User in Blog
        /// </summary>
        /// <param name="username">Name of the user</param>
        /// <param name="password">Password</param>
        /// <param name="email">Email</param>
        /// <param name="firstname">The FirstName</param>
        /// <param name="lastname">The Lastname</param>
        /// <param name="timezone">The Time Zone for the user</param>
        /// <param name="culture">Culture</param>
        /// <param name="requireconfirmation">Always true because the acccount is confirmed inmediately</param>
        /// <param name="selectedroles">Bunch of roles for the user being created</param>
        public void CreateAccount(string username, string password, string email, string firstname, string lastname, string timezone, string culture, bool requireconfirmation, string[] selectedroles)
        {
            var token = CodeFirstSecurity.CreateAccount(username, password, email, firstname, lastname, timezone, culture, requireconfirmation);

            if (selectedroles.Length == 0)
            {
                CodeFirstRoleServices.RemoveUsersFromRoles(new string[1] {
                    username
                }, CodeFirstRoleServices.GetAllRoles());
            }
            else
            {
                CodeFirstRoleServices.RemoveUsersFromRoles(new string[1] {
                    username
                }, CodeFirstRoleServices.GetAllRoles());
                CodeFirstRoleServices.AddUsersToRoles(new string[1] {
                    username
                }, selectedroles);
            }
        }
Exemple #14
0
 /// <summary>
 /// Save changes made in User
 /// </summary>
 /// <param name="role">The User to save</param>
 public void SaveUser(User user, string[] selectedroles)
 {
     UserRepository.Update(user);
     UserRepository.UnitOfWork.Commit();
     if (selectedroles.Length == 0)
     {
         CodeFirstRoleServices.RemoveUsersFromRoles(new string[1] {
             user.Username
         }, CodeFirstRoleServices.GetAllRoles());
     }
     else
     {
         CodeFirstRoleServices.RemoveUsersFromRoles(new string[1] {
             user.Username
         }, CodeFirstRoleServices.GetAllRoles());
         CodeFirstRoleServices.AddUsersToRoles(new string[1] {
             user.Username
         }, selectedroles);
     }
 }
Exemple #15
0
        public ActionResult Videos(int?page, string sortdir, string searchstring)
        {
            if (!String.IsNullOrEmpty(searchstring))
            {
                Session["videosearchstring"] = searchstring;
            }
            else
            {
                Session["videosearchstring"] = String.Empty;
            }
            var pageIndex = page ?? 0;

            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                return(View(MediaServices.FindVideosForRole(true, pageIndex, Session["videosearchstring"].ToString())));
            }
            else
            {
                return(View(MediaServices.FindVideosForRole(false, pageIndex, Session["videosearchstring"].ToString())));
            }
        }
Exemple #16
0
        /// <summary>
        /// Subscribe the latest post in this website
        /// </summary>
        /// <returns>Xml rss 2.0 formatted Posts</returns>
        public ActionResult RssFeed()
        {
            bool ispremium;

            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                ispremium = true;
            }
            else
            {
                ispremium = false;
            }
            var postItems = BlogServices.FindRSSPosts(ispremium, 20)
                            .Select(p => new SyndicationItem(p.Title, p.Description, new Uri(Url.AbsoluteAction("GetPostByCode", "Post", new { id = p.Code })))
            {
                PublishDate = new DateTimeOffset(p.DateCreated),
                Copyright   = new TextSyndicationContent(BgResources.Messages_Copyright),
            });
            var feed = new SyndicationFeed(String.Format(Resources.AppMessages.Rss_Latest_Post_Title, BgResources.Messages_SiteTitle), Resources.AppMessages.Rss_Latest_Post_Description, new Uri(Url.AbsoluteAction("NewPosts", "Post")), postItems);

            return(new FeedResult(new Rss20FeedFormatter(feed)));
        }