/// <summary>
        /// Gets the ip address from current request.
        /// </summary>
        /// <returns></returns>
        public static string GetIpAddressFromCurrentRequest()
        {
            var authorIpAddressObject = CommentsUtilitiesReflector.Reflect("GetIpAddressFromCurrentRequest");
            var authorIpAddress       = authorIpAddressObject as string;

            return(authorIpAddress);
        }
        /// <summary>
        /// Gets the author.
        /// </summary>
        /// <param name="commentData">The comment data.</param>
        /// <returns></returns>
        public static IAuthor GetAuthor(CommentCreateRequest commentData)
        {
            var authorObject = CommentsUtilitiesReflector.Reflect("GetAuthor", commentData);
            var author       = authorObject as IAuthor;

            return(author);
        }
        /// <summary>
        /// Gets the comment response.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <param name="includeSensitiveInformation">if set to <c>true</c> [include sensitive information].</param>
        /// <returns></returns>
        public static CommentResponse GetCommentResponse(IComment comment, bool includeSensitiveInformation = false)
        {
            var commentResponseObject = CommentsUtilitiesReflector.Reflect("GetCommentResponse", comment, includeSensitiveInformation);

            var commentResponse = commentResponseObject as CommentResponse;

            return(commentResponse);
        }
        /// <summary>
        /// Gets the comments by thread for current author with rating.
        /// </summary>
        /// <param name="threadKey">The thread key.</param>
        /// <returns></returns>
        public static IEnumerable <IComment> GetCommentsByThreadForCurrentAuthorWithRating(string threadKey)
        {
            object commentsObject = CommentsUtilitiesReflector.Reflect("GetCommentsByThreadForCurrentAuthorWithRating", threadKey, SystemManager.GetCommentsService());

            var comments = commentsObject as IEnumerable <IComment>;

            return(comments);
        }
Пример #5
0
        public AuthorReviewedViewModel Get(AuthorReviewedGetRequest request)
        {
            var authorComments = CommentsUtilitiesReflector.GetCommentsByThreadForCurrentAuthorWithRating(request.ThreadKey);

            return(new AuthorReviewedViewModel()
            {
                AuthorAlreadyReviewed = authorComments.Any()
            });
        }
Пример #6
0
        private CommentResponse SubmitCommentInternal(CommentCreateRequest commentData, IThread thread, IAuthor author)
        {
            var cs            = SystemManager.GetCommentsService();
            var currentConfig = CommentsUtilitiesReflector.GetThreadConfigByType(thread.Type, thread.Key);

            if (currentConfig.RequiresAuthentication)
            {
                if (author.Key.IsNullOrWhitespace() || author.Key == Guid.Empty.ToString())
                {
                    throw new InvalidOperationException("Comment cannot be submitted at the moment. Please refresh the page and try again.");
                }
            }

            if (currentConfig.EnableRatings)
            {
                if (commentData.Rating == null)
                {
                    throw new InvalidOperationException("A message displayed when ratings are allowed and a comment is submitted without rating.");
                }

                if (CommentsUtilitiesReflector.GetCommentsByThreadForCurrentAuthorWithRating(thread.Key).Any())
                {
                    throw new InvalidOperationException("Only one comment with rating is allowed per user.");
                }
            }

            var authorIp     = CommentsUtilitiesReflector.GetIpAddressFromCurrentRequest();
            var commentProxy = new CommentProxy(commentData.Message, thread.Key, author, authorIp, commentData.Rating);

            commentProxy.CustomData = commentData.CustomData;

            if (currentConfig.RequiresApproval)
            {
                commentProxy.Status = StatusConstants.WaitingForApproval;
            }
            else
            {
                commentProxy.Status = StatusConstants.Published;
            }

            IComment newComment = cs.CreateComment(commentProxy);

            var result = CommentsUtilitiesReflector.GetCommentResponse(newComment, ClaimsManager.GetCurrentIdentity().IsBackendUser);

            if (commentData.Captcha != null)
            {
                CommentsUtilitiesReflector.RemoveCaptchaFromTempStorage(commentData.Captcha.Key);
            }

            ServiceUtility.DisableCache();

            return(result);
        }
        /// <summary>
        /// Gets the type of the thread configuration by.
        /// </summary>
        /// <param name="threadType">Type of the thread.</param>
        /// <returns></returns>
        public static CommentsSettingsElement GetThreadConfigByType(string threadType, string threadKey)
        {
            Type commentsSettingsElementType = Type.GetType("Telerik.Sitefinity.Modules.Comments.Configuration.CommentsSettingsElement, Telerik.Sitefinity");

            object commentsSettingsElementObject = CommentsUtilitiesReflector.Reflect("GetThreadConfigByType", threadType);

            var result = new CommentsSettingsElement()
            {
                AllowComments          = (bool)commentsSettingsElementType.GetProperty("AllowComments").GetValue(commentsSettingsElementObject, null),
                RequiresAuthentication = (bool)commentsSettingsElementType.GetProperty("RequiresAuthentication").GetValue(commentsSettingsElementObject, null),
                RequiresApproval       = (bool)commentsSettingsElementType.GetProperty("RequiresApproval").GetValue(commentsSettingsElementObject, null)
            };

            result.EnableRatings = threadKey.EndsWith("_review", StringComparison.Ordinal);

            return(result);
        }
 /// <summary>
 /// Removes specified key from temp storage.
 /// </summary>
 /// <param name="key">The key.</param>
 public static void RemoveCaptchaFromTempStorage(string key)
 {
     CommentsUtilitiesReflector.Reflect("RemoveCaptchaFromTempStorage", key);
 }
Пример #9
0
        private CommentResponse PostInternal(CommentCreateRequest request)
        {
            CommentsWebServiceReflector.Validate(request);

            CommentResponse result;

            try
            {
                var author = CommentsUtilitiesReflector.GetAuthor(request);
                var cs     = SystemManager.GetCommentsService();
                var thread = cs.GetThread(request.ThreadKey);

                if (thread == null)
                {
                    request.Thread.Key = request.ThreadKey;

                    CommentsWebServiceReflector.Validate(request.Thread);
                    CommentsWebServiceReflector.ValidatePostRequest(request.Thread.Type, request.Captcha, false);

                    var group = cs.GetGroup(request.Thread.GroupKey);
                    if (group == null)
                    {
                        CommentsWebServiceReflector.Validate(request.Thread.Group);

                        request.Thread.Group.Key = request.Thread.GroupKey;

                        var groupProxy = new GroupProxy(request.Thread.Group.Name, request.Thread.Group.Description, author)
                        {
                            Key = request.Thread.Group.Key
                        };
                        group = cs.CreateGroup(groupProxy);
                    }

                    var threadProxy = new ThreadProxy(request.Thread.Title, request.Thread.Type, group.Key, author)
                    {
                        Key        = request.Thread.Key,
                        Language   = request.Thread.Language,
                        DataSource = request.Thread.DataSource,
                        Behavior   = request.Thread.Behavior
                    };

                    thread = cs.CreateThread(threadProxy);
                }
                else
                {
                    if (thread.IsClosed)
                    {
                        throw new InvalidOperationException("Thread is closed.");
                    }

                    CommentsWebServiceReflector.ValidatePostRequest(thread.Type, request.Captcha, false);
                }

                result = this.SubmitCommentInternal(request, thread, author);
            }
            catch (InvalidOperationException ex)
            {
                throw new InvalidOperationException("Comment cannot be submitted at the moment. Please refresh the page and try again.", ex);
            }

            ServiceUtility.DisableCache();

            return(result);
        }