Ejemplo n.º 1
0
        /// <summary>
        /// Add new blog
        /// </summary>
        /// <param name="item">Blog item</param>
        /// <returns>Saved blog with new ID</returns>
        public Models.Blog Add(BlogItem item)
        {
            // has to be on primary blog and be an admin
            // or blog allows create new on self registration
            if (!(Blog.CurrentInstance.IsPrimary && (Security.IsAdministrator || BlogSettings.Instance.CreateBlogOnSelfRegistration)))
            {
                throw new UnauthorizedAccessException();
            }

            string message;

            if (!BlogGenerator.ValidateProperties(item.Name, item.UserName, item.Email, out message))
            {
                throw new ApplicationException(message);
            }

            var coreBlog = BlogGenerator.CreateNewBlog(item.Name, item.UserName, item.Email, item.Password, out message);

            if (coreBlog == null || !string.IsNullOrWhiteSpace(message))
            {
                throw new ApplicationException("Failed to create the new blog.");
            }

            return(ToJson(coreBlog));
        }
Ejemplo n.º 2
0
        string CreateNewBlog()
        {
            string message = string.Empty;
            Blog   blog    = null;

            if (!BlogGenerator.ValidateProperties(BlogName.Text, UserName.Text, Email.Text, out message))
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = "Validation for new blog failed.";
                }
                return(message);
            }

            blog = BlogGenerator.CreateNewBlog(BlogName.Text, UserName.Text, Email.Text, Password.Text, out message);

            if (blog == null || !string.IsNullOrWhiteSpace(message))
            {
                return(message ?? "Failed to create the new blog.");
            }

            return(message);
        }
Ejemplo n.º 3
0
        string CreateNewBlog()
        {
            string message = string.Empty;
            Blog   blog    = null;

            if (!BlogGenerator.ValidateProperties(BlogName.Text, UserName.Text, Email.Text, out message))
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = "Validation for new blog failed.";
                }
                return(message);
            }

            // recaptcha check
            SetCaptcha(Form.Controls);

            if (captcha != null)
            {
                captcha.Validate();

                if (!captcha.IsValid)
                {
                    message = "Captcha invalid.";
                    return(message);
                }
            }

            blog = BlogGenerator.CreateNewBlog(BlogName.Text, UserName.Text, Email.Text, Password.Text, out message);

            if (blog == null || !string.IsNullOrWhiteSpace(message))
            {
                return(message ?? "Failed to create the new blog.");
            }

            return(message);
        }