상속: RaccoonBlog.Web.Models.Model
예제 #1
0
		public virtual ActionResult CreateBlog(BlogConfig config)
		{
			var result = AssertConfigurationIsNeeded();
			if (result != null)
				return result;

			if (!ModelState.IsValid)
				return View("Index");

			// Create the blog by storing the config
			config.Id = "Blog/Config";
			RavenSession.Store(config);

			// Create default sections
			RavenSession.Store(new Section { Title = "Archive", IsActive = true, Position = 1, ControllerName = "Section", ActionName = "ArchivesList" });
			RavenSession.Store(new Section { Title = "Tags", IsActive = true, Position = 2, ControllerName = "Section", ActionName = "TagsList" });
			RavenSession.Store(new Section { Title = "Statistics", IsActive = true, Position = 3, ControllerName = "Section", ActionName = "PostsStatistics" });
			
			var user = new User
			{
				FullName = "Default User",
				Email = config.OwnerEmail,
				Enabled = true,
			}.SetPassword("raccoon");
			RavenSession.Store(user);

			return RedirectToAction("Success", config);
		}
예제 #2
0
        public ActionResult CreateBlog(BlogConfig config)
        {
            AssertConfigurationIsNeeded();

            if (!ModelState.IsValid)
                return View("Index");

            // Create the blog by storing the config
            config.Id = "Blog/Config";
            Session.Store(config);

            // Create default sections
            Session.Store(new Section { Title = "Archive", IsActive = true, Position = 1, ControllerName = "Section", ActionName = "ArchivesList" });
            Session.Store(new Section { Title = "Tags", IsActive = true, Position = 2, ControllerName = "Section", ActionName = "TagsList" });
            Session.Store(new Section { Title = "Statistics", IsActive = true, Position = 3, ControllerName = "Section", ActionName = "PostsStatistics" });
            var user = new User
            {
                FullName = "Default User",
                Email = "*****@*****.**",
                Enabled = true,
            };
            user.SetPassword("raccoon");
            Session.Store(user);

            return RedirectToAction("Success");
        }
예제 #3
0
        public virtual ActionResult Index(BlogConfig config)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Message = ModelState.FirstErrorMessage();
                if (Request.IsAjaxRequest())
                    return Json(new { Success = false, ViewBag.Message });
                return View(BlogConfig);
            }

            var current = RavenSession.Load<BlogConfig>(BlogConfig.Key);
            if (IsFuturePostsEncryptionOptionsChanged(current, config))
            {
                RemoveFutureRssAccessOnEncryptionConfigChange();
            }

            RavenSession.Advanced.Evict(current);
            RavenSession.Store(config, BlogConfig.Key);
            RavenSession.SaveChanges();

            OutputCacheManager.RemoveItem(MVC.Section.Name, MVC.Section.ActionNames.ContactMe);

            ViewBag.Message = "Configurations successfully saved!";
            if (Request.IsAjaxRequest())
                return Json(new { Success = true, ViewBag.Message });
            return View(config);
        }
예제 #4
0
 public static Credentials GetCredentials(BlogConfig blogConfig)
 {
     return new Credentials()
     {
         User = blogConfig.RedditUser,
         Password = blogConfig.RedditPassword
     };
 }
예제 #5
0
        public static IList<string> ParseSubreddits(BlogConfig config)
        {
            if (string.IsNullOrEmpty(config.RedditSubredditsToSubmitToOnPublish))
                return new List<string>();

            return config.RedditSubredditsToSubmitToOnPublish
                .Split(',')
                .Select(x => x.Trim())
                .ToList();
        }
예제 #6
0
		public void WhenTheBlogConfigIsAvailable_ThePropertyShouldReturnTheConfig()
		{
			var config = new BlogConfig {Title = "Test Config", Id = "blog/config"};
			SetupData(session => session.Store(config));

			BlogConfig configFromController = null;
			ExecuteAction<LoginController>(controller => configFromController = controller.BlogConfig);

			Assert.Equal(config.Title, configFromController.Title);
		}
예제 #7
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.IsChildAction)
                return;

            var blogConfig = Session.Load<BlogConfig>("Blog/Config");
            if (blogConfig == null)
            {
                blogConfig = new BlogConfig();
                Session.Store(blogConfig);
            }
            ViewBag.BlogConfig = blogConfig.MapTo<BlogConfigViewModel>();
        }
        public ActionResult Index(BlogConfig config)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Message = ModelState.FirstErrorMessage();
                if (Request.IsAjaxRequest())
                    return Json(new { Success = false, ViewBag.Message });
                return View(BlogConfig);
            }

            RavenSession.Store(config);

            ViewBag.Message = "Configurations successfully saved!";
            if (Request.IsAjaxRequest())
                return Json(new { Success = true, ViewBag.Message });
            return View(config);
        }
예제 #9
0
		public virtual ActionResult Index(BlogConfig config)
		{
			if (ModelState.IsValid == false)
			{
				ViewBag.Message = ModelState.FirstErrorMessage();
				if (Request.IsAjaxRequest())
					return Json(new { Success = false, ViewBag.Message });
				return View(BlogConfig);
			}

			RavenSession.Store(config, "Blog/Config");

			OutputCacheManager.RemoveItem(MVC.Section.Name, MVC.Section.ActionNames.ContactMe);

			ViewBag.Message = "Configurations successfully saved!";
			if (Request.IsAjaxRequest())
				return Json(new { Success = true, ViewBag.Message });
			return View(config);
		}
예제 #10
0
 private static CryptographyUtil GetCrypto(BlogConfig blogConfig)
 {
     return new CryptographyUtil(blogConfig.FuturePostsEncryptionSalt, blogConfig.FuturePostsEncryptionIv);
 }
예제 #11
0
 public static FutureRssAccessToken Parse(string token, BlogConfig blogConfig)
 {
     var json = GetCrypto(blogConfig).Decrypt(token, blogConfig.FuturePostsEncryptionKey);
     return JsonConvert.DeserializeObject<FutureRssAccessToken>(json);
 }
예제 #12
0
 public string GetToken(BlogConfig blogConfig)
 {
     return GetCrypto(blogConfig).Encrypt(JsonConvert.SerializeObject(this), blogConfig.FuturePostsEncryptionKey);
 }
예제 #13
0
 private bool IsFuturePostsEncryptionOptionsChanged(BlogConfig current, BlogConfig config)
 {
     return current.FuturePostsEncryptionKey != config.FuturePostsEncryptionKey ||
            current.FuturePostsEncryptionIv != config.FuturePostsEncryptionIv ||
            current.FuturePostsEncryptionSalt != config.FuturePostsEncryptionSalt;
 }