Пример #1
0
        public string Delete(string uid)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            Guid guid = Guid.Empty;
            if (Guid.TryParse(uid, out guid))
            {
                try
                {
                    TemplatePlugin.Instance.Delete(guid /*uid*/);
                    output.AddOutput("uid", uid);
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #2
0
        public string Update(string locale, 
            bool isCommentModerated)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            //get the configuration.
            SiteConfiguration configuration = SiteConfiguration.Read();
            if (!string.IsNullOrEmpty(locale))
            {
                configuration.Locale = locale;
            }

            configuration.IsCommentModerationOn = isCommentModerated;

            try
            {
                configuration.Update();
                output.Success = true;
            }
            catch (MessageException me)
            {
                output.AddOutput(Constants.Json.Error, me.Message);
            }

            return output.GetJson();
        }
Пример #3
0
        public string AddReponse(string form, string fields)
        {
            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            formsmanage.AddFormEntry(form, Guid.Empty, fields, output);

            return output.GetJson();
        }
Пример #4
0
        public string Delete(string path)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            CollectionPathPlugin.Instance.Delete(CollectionPath.KeyName, path);
            output.AddOutput("path", path);
            output.Success = true;

            return output.GetJson();
        }
Пример #5
0
        public string DeleteUser(string alias)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(alias))
            {
                output.Success = UserStore.Instance.DeleteUser(alias);
            }

            return output.GetJson();
        }
Пример #6
0
        public string Update(bool isLogEnabled, string logLevel)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            //get the configuration.
            Configuration configuration = Configuration.Instance;
            configuration.IsLoggingOn = isLogEnabled;

            //logging level
            LogLevel level = LogLevel.Info;
            if (!Enum.TryParse<LogLevel>(logLevel, out level))
            {
                level = LogLevel.Info;
            }

            configuration.LoggingLevel = level;

            try
            {
                configuration.Update();

                // apply the logging
                Jardalu.Ratna.Utilities.Logger.IsEnabled = Configuration.Instance.IsLoggingOn;
                Jardalu.Ratna.Utilities.Logger.EnabledLevel = Configuration.Instance.LoggingLevel;

                output.Success = true;
            }
            catch (MessageException me)
            {
                output.AddOutput(Constants.Json.Error, me.Message);
            }

            return output.GetJson();
        }
Пример #7
0
        public string Delete(string url)
        {
            // make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(url))
            {
                MediaStore.Instance.Delete(url);
                output.Success = true;
            }

            return output.GetJson();
        }
Пример #8
0
        public string SearchGroup(string query)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(query))
            {
                //find user or group
                Principal principal = PrincipalStore.Instance.Find(query);
                if (principal != null)
                {
                    bool isGroup = false;

                    if (principal.GetType() == typeof(Group))
                    {
                        isGroup = true;

                        // add name, principalid, group properties
                        output.AddOutput("name", principal.Name);
                        output.AddOutput("principalId", principal.PrincipalId);
                        output.AddOutput("isGroup", isGroup);

                        this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod());

                        output.Success = true;
                    }
                }
            }

            return output.GetJson();
        }
Пример #9
0
        public string AddPhotos(string url, string[] photos)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(url))
            {
                // read the gallery
                Gallery gallery = GalleryPlugin.Instance.Read(url);

                if (gallery != null && photos != null && photos.Length > 0)
                {
                    foreach (string photo in photos)
                    {
                        if (!string.IsNullOrEmpty(photo))
                        {
                            // add image to the gallery
                            gallery.Add(photo);
                        }
                    }
                }

                //save
                GalleryPlugin.Instance.Save(gallery);
                output.Success = true;
            }

            return output.GetJson();
        }
Пример #10
0
        public string ValidateUrlKey(string urlKey)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {

                //make sure the url is relative and valid.
                if (Uri.IsWellFormedUriString(urlKey, UriKind.Relative))
                {
                    output.Success = !ArticleStore.Instance.Exists(urlKey);
                }
            }

            return output.GetJson();
        }
Пример #11
0
        public string AddComment(string key, string name, string email, string url, string body, string permalink, string threadrenderer)
        {
            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (string.IsNullOrEmpty(name) ||
                !Utility.IsValidEmail(email) ||
                string.IsNullOrEmpty(body))
            {
                // not a valid comment
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Comments.Invalid"));
            }
            else
            {
                // image for the thread user.
                string imageUrl = null;

                RatnaUser user = base.ValidatedUser();

                if (user != null)
                {
                    imageUrl = user.Photo;
                }

                // save the comment
                Comment comment = new Comment();
                comment.Key = key;
                comment.Id = Utility.GetUniqueString();
                comment.Body = body;
                comment.Name = name;
                comment.Url = url;
                comment.Email = email;
                comment.Image = imageUrl;
                if (!string.IsNullOrEmpty(permalink))
                {
                    comment.PermaLink = permalink;
                }

                // invoke apps before saving comment
                AppEngine.ExecuteApps(AppEvent.CommentSaving, comment);

                // check for settings to put the comment in pending list
                SiteConfiguration config = SiteConfiguration.Read();
                if (config.IsCommentModerationOn)
                {
                    comment.Approved = false;
                }

                logger.Log(LogLevel.Info, "Saving comment from : {0}, key: {1}, id: {2}", comment.Email, comment.Key, comment.Id);
                CommentsPlugin.Instance.Add(comment);
                output.Success = true;

                //notify
                Notifier.Notify(string.Format(ResourceManager.GetLiteral("Comments.NewCommentSubject"), comment.Name) /* subject */,
                                string.Format(ResourceManager.GetLiteral("Comments.NewCommentBody"), comment.Name, comment.PermaLink) /* body */);

                // add the snippet code
                if (!string.IsNullOrEmpty(threadrenderer))
                {
                    string oneRowOutput = GetOneRowOutput(threadrenderer, imageUrl, name, DateTime.Now.ToString(), url, body);

                    if (oneRowOutput != null)
                    {
                        logger.Log(LogLevel.Debug, "Got thread control [{0}] output.", threadrenderer);
                        string jsonHtml = Jardalu.Ratna.Web.Utility.SanitizeJsonHtml(oneRowOutput);
                        output.AddOutput(Constants.Json.Html, jsonHtml);
                    }
                }

                // invoke apps after comments saved
                AppEngine.ExecuteApps(AppEvent.CommentSaved, comment);
            }

            return output.GetJson();
        }
Пример #12
0
        public string Save(string path, string title, string pathType, int pagesize, string nav)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            CollectionPath collectionPath = CollectionPathPlugin.Instance.Read(path);

            if (collectionPath == null)
            {
                collectionPath = new CollectionPath();
                collectionPath.Path = path;
            }

            collectionPath.Title = title;
            collectionPath.Navigation = nav ?? string.Empty;
            collectionPath.PageSize = pagesize > 0 ? pagesize : 4;

            CollectionType collectionType;
            if (!Enum.TryParse<CollectionType>(pathType, true, out collectionType))
            {
                collectionType = CollectionType.BlogArticle;
            }

            // set the collection type
            collectionPath.CollectionType = collectionType;

            try
            {
                //save
                CollectionPathPlugin.Instance.Update(collectionPath);

                output.Success = true;
            }
            catch (MessageException me)
            {
                output.AddOutput(Constants.Json.Error, me.Message);
            }

            return output.GetJson();
        }
Пример #13
0
        public string Delete(string urlKey)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    ArticleStore.Instance.Delete(urlKey);

                    // add the location to the output as well.
                    output.AddOutput("urlKey", urlKey);
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #14
0
        public string MarkForReview(string urlKey)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    ArticleStore.Instance.Publish(urlKey);

                    // get the title for the article
                    Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.InReview);

                    // add the location to the output as well.
                    output.AddOutput("urlKey", urlKey);
                    output.AddOutput("title", article.Title);
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #15
0
        public string Publish(string urlKey)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    logger.Log(LogLevel.Debug, "Publishing article at url - {0}", urlKey);

                    ArticleStore.Instance.Publish(urlKey);

                    logger.Log(LogLevel.Info, "Article published at url - {0}", urlKey);

                    // get the title for the article
                    Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Published);

                    logger.Log(LogLevel.Debug, "Version of the published article - {0}", article.Version);

                    // add the location to the output as well.
                    output.AddOutput("urlKey", urlKey);
                    output.AddOutput("title", article.Title);

                    // published article must move to the published column. snippet generation.
                    this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod());

                    output.Success = true;
                }
                catch (MessageException me)
                {
                    logger.Log(LogLevel.Error, "Unable to publish article. Exception - {0}", me);
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #16
0
        public string UpdateCustomResponses(
            string error404,
            string error500,
            string otherErrors)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            //get the custom response.
            CustomResponse customResponse = CustomResponse.Read();

            customResponse.PageNotFound = error404;
            customResponse.InteralServerError = error500;
            customResponse.OtherErrors = otherErrors;

            try
            {
                customResponse.Update();
                output.Success = true;
            }
            catch (MessageException me)
            {
                output.AddOutput(Constants.Json.Error, me.Message);
            }

            return output.GetJson();
        }
Пример #17
0
        public string PublishMultiple(string urlKeys)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKeys))
            {
                try
                {
                    string[] tokens = urlKeys.Split(',');
                    List<string> urlList = new List<string>();

                    foreach (string token in tokens)
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            urlList.Add(token);
                            logger.Log(LogLevel.Info, "Adding article at url '{0}' to get published", token);
                        }
                    }

                    logger.Log(LogLevel.Info, "Calling publish on multiple articles");
                    ArticleStore.Instance.Publish(urlList);
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #18
0
        public string AddField(string formname, string fieldname, string fieldtype, string required)
        {
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            bool validFieldName = true;

            if (string.IsNullOrEmpty(fieldname) ||
                !Regex.IsMatch(fieldname, "^[0-9a-zA-Z]+$"))
            {
                // field name with space and alpha numbers
                validFieldName = false;
            }

            if (validFieldName)
            {
                #region field name is valid

                FieldType ft = FieldType.Other;

                if (Enum.TryParse<FieldType>(fieldtype, true, out ft))
                {
                    bool isRequired = false;
                    bool success = false;

                    if (!Boolean.TryParse(required, out isRequired))
                    {
                        isRequired = false;
                    }

                    Form form = null;

                    if (!string.IsNullOrEmpty(formname))
                    {
                        FormsPlugin.Instance.TryRead(formname, out form);
                    }

                    if (form != null)
                    {
                        // if the field already exists, error out.
                        if (form.Fields.Contains(new Field() { Name = fieldname }))
                        {
                            output.AddOutput(Constants.Json.Error,
                                ResourceManager.GetLiteral("Admin.Forms.Field.Save.Error.FieldNameInUse"));
                        }
                        else
                        {
                            //add the field to the form
                            form.AddField(fieldname, ft, isRequired);
                            FormsPlugin.Instance.Save(form);
                            success = true;
                        }

                    }

                    if (success)
                    {
                        this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod());
                        output.Success = true;
                    }
                }

                #endregion
            }
            else
            {
                output.AddOutput(Constants.Json.Error,
                    ResourceManager.GetLiteral("Admin.Forms.Field.Save.Error.FieldNameInInvalid"));
            }

            return output.GetJson();
        }
Пример #19
0
        public string RemoveImage(string urlKey, string images)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {

                    // photos can't be added to published articles
                    Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Draft);
                    if (article != null)
                    {

                        //multiple images can be deleted at the same time.
                        if (images != null)
                        {
                            //check if there are multiple images to be deleted.
                            string[] tokens = images.Split(',');

                            if (tokens.Length > 0 && BlogArticleHandler.CanHandle(article))
                            {
                                BlogArticle blogArticle = new BlogArticle(article);
                                foreach (string token in tokens)
                                {
                                    if (!string.IsNullOrEmpty(token))
                                    {
                                        blogArticle.RemoveImage(token);
                                    }
                                }
                                blogArticle.Update();
                                output.Success = true;
                            }
                        }
                    }
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
                catch
                {
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Update.Error"));
                }
            }

            return output.GetJson();
        }
Пример #20
0
        public string Update(string displayName, string firstName, string lastName, string description)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            // set the user data
            user.DisplayName = displayName;
            user.FirstName = firstName;
            user.LastName = lastName;
            user.Description = description;

            try
            {
                UserStore.Instance.UpdateUser(user);
                output.Success = true;
            }
            catch(Exception ex)
            {
                // log the error
                MessageException me = ex as MessageException;
                if (me != null)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }

                logger.Log(LogLevel.Debug, "Unable to update user : {0}", ex);
            }

            return output.GetJson();
        }
Пример #21
0
        public string SavePageMetadata(string urlKey, string navigationtab, string tags, string description, string head)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    bool exists = ArticleStore.Instance.Exists(urlKey);

                    if (exists)
                    {

                        StaticArticle article = new StaticArticle();
                        article.UrlKey = urlKey;
                        article.Read(PublishingStage.Draft);
                        article.RemoveTags();

                        ((INavigationTag)article).Name = navigationtab ?? string.Empty;;

                        if (!string.IsNullOrEmpty(tags))
                        {
                            article.AddTags(tags);
                        }

                        article.Head = head ?? string.Empty;
                        article.Description = description ?? string.Empty;
                        article.Update();

                        output.Success = true;
                    }
                }
                catch (MessageException me)
                {
                    logger.Log(LogLevel.Error, "Unable to save article metadata. MessageException - {0}", me);
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, "Unable to save article metadata. Exception - {0}", ex);
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error"));
                }
            }

            return output.GetJson();
        }
Пример #22
0
        public string SavePage(string urlKey, string title, string body)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                //make sure the url is relative and valid.
                if (!Uri.IsWellFormedUriString(urlKey, UriKind.Relative))
                {
                    // failed because URL is not valid.
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Url.Validate.Error"));
                }
                else
                {
                    try
                    {
                        bool exists = ArticleStore.Instance.Exists(urlKey);

                        StaticArticle article = new StaticArticle();
                        article.UrlKey = urlKey;

                        // if the article already exists, read the article
                        // to sync with latest version
                        if (exists)
                        {
                            article.Read(PublishingStage.Draft);
                        }

                        article.Title = title;
                        article.Body = body;

                        if (!exists)
                        {
                            article.Owner = user;
                            article.Create();
                        }
                        else
                        {
                            article.Update();
                        }

                        output.Success = true;
                    }
                    catch (MessageException me)
                    {
                        logger.Log(LogLevel.Error, "Unable to save page. MessageException - {0}", me);
                        output.AddOutput(Constants.Json.Error, me.Message);
                    }
                    catch (Exception ex)
                    {
                        logger.Log(LogLevel.Error, "Unable to save page. Exception - {0}", ex);
                        output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error"));
                    }
                }
            }

            return output.GetJson();
        }
Пример #23
0
        public string AddImages(string urlKey, string[] images)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {

                    // photos can't be added to published articles
                    Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Draft);
                    if (article != null)
                    {
                        if (BlogArticleHandler.CanHandle(article))
                        {
                            BlogArticle blogArticle = new BlogArticle(article);

                            foreach (string image in images)
                            {
                                blogArticle.AddImage(image);
                            }

                            blogArticle.Update();
                            output.Success = true;
                        }
                    }
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
                catch
                {
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Update.Error"));
                }
            }

            return output.GetJson();
        }
Пример #24
0
        public string Revert(string urlKey, int version)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    ArticleStore.Instance.Revert(urlKey, version);
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }

            return output.GetJson();
        }
Пример #25
0
        public string Save(string uid, string url, string name, string description, string nav)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            Guid guid = Guid.Empty;
            if (Guid.TryParse(uid, out guid))
            {
                try
                {
                    // make sure name, and url are not empty
                    if (string.IsNullOrEmpty(name) ||
                        string.IsNullOrEmpty(url) ||
                        !Uri.IsWellFormedUriString(url, UriKind.Relative) ||
                        !url.StartsWith("/"))
                    {
                        throw new MessageException(ResourceManager.GetLiteral("Admin.Media.Gallery.Error.NameUrlInvalid"));
                    }

                    Gallery gallery = ReadOrThrow(guid, name, url, description, nav);

                    if (gallery != null)
                    {

                        GalleryPlugin.Instance.Save(gallery);

                        output.AddOutput("uid", gallery.UId);
                        output.Success = true;
                    }
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }

            }

            return output.GetJson();
        }
Пример #26
0
 protected string SendAccessDenied()
 {
     ServiceOutput output = new ServiceOutput();
     output.Success = false;
     output.AddOutput(Constants.Json.Message, ResourceManager.GetLiteral("Admin.Common.AccessDenied"));
     return output.GetJson();
 }
Пример #27
0
        public string Delete(string url)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(url))
            {
                GalleryPlugin.Instance.Delete(Gallery.KeyName, url);

                // add the location to the output as well.
                output.AddOutput("url", url);
                output.Success = true;
            }

            return output.GetJson();
        }
Пример #28
0
        public string UpdateNotification(
            string notificationEmail,
            bool comment,
            bool formsResponse
            )
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            bool validEmail = Utility.IsValidEmail(notificationEmail);

            if (validEmail)
            {
                //get the configuration.
                NotificationConfiguration configuration = NotificationConfiguration.Read();
                configuration.NotifyToEmail = notificationEmail;
                configuration.NotifyOnComment = comment;
                configuration.NotifyOnFormResponse = formsResponse;

                try
                {
                    configuration.Update();
                    output.Success = true;
                }
                catch (MessageException me)
                {
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
            }
            else
            {
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Errors.InvalidEmailAddress"));
            }

            return output.GetJson();
        }
Пример #29
0
        public string SaveTemplate(string uid, string name, string url, string path, string master, bool active)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            Guid guid = Guid.Empty;
            if (Guid.TryParse(uid, out guid))
            {

                if (!string.IsNullOrEmpty(name) &&
                    !string.IsNullOrEmpty(url) &&
                    !string.IsNullOrEmpty(path) &&
                    !string.IsNullOrEmpty(master))
                {

                    try
                    {
                        // save the template
                        Template template = new Template()
                        {
                            Name = name,
                            TemplatePath = path,
                            MasterFileName = master,
                            UrlPath = url,
                            UId = guid
                        };

                        // add the template
                        TemplatePlugin.Instance.Add(template);

                        if (active)
                        {
                            TemplatePlugin.Instance.Activate(template);
                        }
                        else
                        {
                            TemplatePlugin.Instance.Deactivate(template);
                        }

                        output.Success = true;
                    }
                    catch (MessageException me)
                    {
                        output.AddOutput(Constants.Json.Error, me.Message);
                    }
                }
            }

            return output.GetJson();
        }
Пример #30
0
        public string UpdateSmtp(
            string smtpAddress,
            string smtpUserName,
            string smtpPassword,
            string smtpFrom)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            //get the configuration.
            NotificationConfiguration configuration = NotificationConfiguration.Read();

            configuration.SmtpUserName = smtpUserName;
            if (!string.IsNullOrEmpty(smtpPassword))
            {
                configuration.SmtpPassword = smtpPassword;
            }
            configuration.SmtpAddress = smtpAddress;

            // if the from is specified, it must be email address
            if (!string.IsNullOrEmpty(smtpFrom) &&  Utility.IsValidEmail(smtpFrom))
            {
                configuration.FromAddress = smtpFrom;
            }

            try
            {
                configuration.Update();
                output.Success = true;
            }
            catch (MessageException me)
            {
                output.AddOutput(Constants.Json.Error, me.Message);
            }

            return output.GetJson();
        }