Пример #1
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");
        }
Пример #2
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);
		}
        public ActionResult Post(UserInput SendInfo)
        {
            User newUser = new User();
            newUser.Email = SendInfo.Email;
            newUser.SetPassword(SendInfo.Password);
            RavenSession.Store(newUser);

            return Json(new { success = true });
        }
Пример #4
0
		public ContactMeViewModel(User user)
		{
			if (user == null)
				return;

			FullName = user.FullName;
			Email = user.Email;
			Phone = user.Phone;
		}
Пример #5
0
		public virtual ActionResult Add(UserInput input)
		{
			if (!ModelState.IsValid)
				return View("Edit", input);

			var user = new User();
			input.MapPropertiesToInstance(user);
			RavenSession.Store(user);
			return RedirectToAction("Index");
		}
Пример #6
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment, User postAuthor)
        {
            if (_requestValues.IsAuthenticated)
                return; // we don't send email for authenticated users

            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = HttpUtility.HtmlDecode(post.Title);
            viewModel.PostSlug = SlugConverter.TitleToSlug(post.Title);
            viewModel.BlogName = DocumentSession.Load<BlogConfig>("Blog/Config").Title;
            viewModel.Key = post.ShowPostEvenIfPrivate.MapTo<string>();

            var subject = string.Format("{2}Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName, comment.IsSpam ? "[Spam] " : string.Empty);

            TaskExecutor.ExcuteLater(new SendEmailTask(viewModel.Email, subject, "NewComment", postAuthor.Email, viewModel));
        }
Пример #7
0
		private static void ImportDatabase(IDocumentStore store)
		{
			Stopwatch sp = Stopwatch.StartNew();

			using (var e = new SubtextEntities())
			{
				Console.WriteLine("Starting...");

				IOrderedEnumerable<Post> theEntireDatabaseOhMygod = e.Posts
					.Include("Comments")
					.Include("Links")
					.Include("Links.Categories")
					.ToList()
					.OrderBy(x => x.DateSyndicated);

				Console.WriteLine("Loading data took {0:#,#} ms", sp.ElapsedMilliseconds);

				var usersList = new List<User>();
				using (IDocumentSession s = store.OpenSession())
				{
					var users = new[]
					{
						new {Email = "*****@*****.**", FullName = "Ayende Rahien", TwitterNick = "ayende", RelatedTwitterNick=(string)null},
						new {Email = "*****@*****.**", FullName = "Fitzchak Yitzchaki", TwitterNick = "fitzchak", RelatedTwitterNick="ayende"},
					};
					for (int i = 0; i < users.Length; i++)
					{
						var user = new User
							{
								Id = "users/" + (i + 1),
								Email = users[i].Email,
								FullName = users[i].FullName,
								TwitterNick = users[i].TwitterNick,
								RelatedTwitterNick = users[i].RelatedTwitterNick,
								Enabled = true,
							};
						user.SetPassword("123456");
						s.Store(user);
						usersList.Add(user);
					}
					s.SaveChanges();
				}

				foreach (Post post in theEntireDatabaseOhMygod)
				{
					var ravenPost = new Web.Models.Post
						{
							AuthorId = usersList
									.Where(u=> u.FullName == post.Author)
									.Select(u => u.Id)
									.FirstOrDefault() ?? 
									usersList.First().Id,
							CreatedAt = new DateTimeOffset(post.DateAdded),
							PublishAt = new DateTimeOffset(post.DateSyndicated ?? post.DateAdded),
							Body = post.Text,
							LegacySlug = post.EntryName,
							Title = HttpUtility.HtmlDecode(post.Title),
							Tags = post.Links.Select(x => x.Categories.Title)
								.Where(x => x != "Uncategorized")
								.ToArray(),
							AllowComments = true
						};

					var commentsCollection = new PostComments();
					commentsCollection.Comments = post.Comments
						.Where(comment => comment.StatusFlag == 1)
						.OrderBy(comment => comment.DateCreated)
						.Select(
							comment => new PostComments.Comment
								{
									Id = commentsCollection.GenerateNewCommentId(),
									Author = comment.Author,
									Body = ConvertCommentToMarkdown(comment.Body),
									CreatedAt = comment.DateCreated,
									Email = comment.Email,
									Url = comment.Url,
									Important = comment.IsBlogAuthor ?? false,
									UserAgent = comment.UserAgent,
									UserHostAddress = comment.IpAddress,
									IsSpam = false,
									CommenterId = null,
								}
						).ToList();
					commentsCollection.Spam = post.Comments
						.Where(comment => comment.StatusFlag != 1)
						.OrderBy(comment => comment.DateCreated)
						.Select(
							comment => new PostComments.Comment
								{
									Id = commentsCollection.GenerateNewCommentId(),
									Author = comment.Author,
									Body = ConvertCommentToMarkdown(comment.Body),
									CreatedAt = comment.DateCreated,
									Email = comment.Email,
									Url = comment.Url,
									Important = comment.IsBlogAuthor ?? false,
									UserAgent = comment.UserAgent,
									UserHostAddress = comment.IpAddress,
									IsSpam = true,
									CommenterId = null,
								}
						).ToList();

					ravenPost.CommentsCount = commentsCollection.Comments.Count;

					using (IDocumentSession s = store.OpenSession())
					{
						s.Store(commentsCollection);
						ravenPost.CommentsId = commentsCollection.Id;

						s.Store(ravenPost);
						commentsCollection.Post = new PostComments.PostReference
						{
							Id = ravenPost.Id,
							PublishAt = ravenPost.PublishAt
						};

						s.SaveChanges();
					}
				}
			}
			Console.WriteLine(sp.Elapsed);
		}
Пример #8
0
 private static Dictionary<string, User> ImportUserList(IDocumentStore store, BlogMLBlog blog)
 {
     var usersList = new Dictionary<string, User>();
     using (var s = store.OpenSession())
     {
         for (int i = 0; i < blog.Authors.Count; ++i)
         {
             var user = new User
                 {
                     Id = "users/" + (i + 1),
                     FullName = blog.Authors[i].Title,
                     Email = blog.Authors[i].Email,
                     Enabled = blog.Authors[i].Approved,
                 };
             user.SetPassword("123456");
             s.Store(user);
             usersList.Add(blog.Authors[i].ID, user);
         }
         s.SaveChanges();
     }
     return usersList;
 }