Ejemplo n.º 1
0
        public async Task <ActionResult> FeedbackAdd_Partial(AddModel model)
        {
            FeedbackConfigData config = await FeedbackConfigDataProvider.GetConfigAsync();

            model.RequireName  = config.RequireName;
            model.RequireEmail = config.RequireEmail;
            model.ShowCaptcha  = config.Captcha;

            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (FeedbackDataProvider dataProvider = new FeedbackDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    throw new InternalError("Feedback couldn't be sent");
                }

                Emails emails = new Emails(Manager);
                await emails.SendFeedbackAsync(config.Email, model.Email, model.Subject, model.Message, model.Name, config.BccEmails?Manager.CurrentSite.AdminEmail : null);

                return(FormProcessed(model, this.__ResStr("okSaved", "Your message has been sent!"), NextPage: Manager.ReturnToUrl));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> SiteAnnouncement_Partial(AddModel model)
        {
            model.UpdateData();
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            if (model.TestMode)
            {
                return(FormProcessed(model, model.Message, model.Title, OnClose: OnCloseEnum.UpdateInPlace, OnPopupClose: OnPopupCloseEnum.UpdateInPlace, PopupOptions: "{encoded:true, canClose: true, autoClose: 0}"));
            }
            else
            {
                using (SiteAnnouncementDataProvider siteAnnounceDP = new SiteAnnouncementDataProvider()) {
                    await YetaWF_Messenger_SiteAnnouncementsHub.SendMessageAsync(model.Message, model.Title);

                    if (await siteAnnounceDP.IsInstalledAsync())
                    {
                        if (!await siteAnnounceDP.AddItemAsync(model.GetData()))
                        {
                            throw new Error(this.__ResStr("noLog", "Message sent. New site announcement log record couldn't be added"));
                        }
                    }
                }
                return(FormProcessed(model));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> SiteAdd_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            SiteDefinition currentSite = Manager.CurrentSite;

            SiteDefinition newSite = model.GetData();
            await newSite.AddNewAsync();

            Manager.CurrentSite = newSite;
            try {
                PackagesDataProvider packagesDP = new PackagesDataProvider();
                await packagesDP.InitNewAsync(true);
            } catch (Exception) {
                throw;
            } finally {
                Manager.CurrentSite = currentSite;
            }

            string nextPage = Manager.CurrentSite.MakeUrl(RealDomain: Manager.CurrentSite.SiteDomain);

            Manager.RestartSite();

            return(FormProcessed(model, this.__ResStr("okSaved", "New site \"{0}\" created - Click OK to populate the new site with the current site template.(+nl)(+nl)IMPORTANT: This site is not accessible by its Url until the domain \"{0}\" is defined in IIS and in the hosts file.", newSite.SiteDomain),
                                 NextPage: nextPage));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> CommentAdd_Partial(AddModel model)
        {
            await model.UpdateDataAsync();

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry blogEntry = await entryDP.GetItemAsync(model.EntryIdentity);

                if (blogEntry == null)
                {
                    throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found."), model.EntryIdentity);
                }
                if (!blogEntry.OpenForComments)
                {
                    throw new InternalError("Can't add comments to this blog entry");
                }
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }
                using (BlogCommentDataProvider blogCommentDP = new BlogCommentDataProvider(model.EntryIdentity)) {
                    BlogComment blogComment = model.GetData();
                    if (!await blogCommentDP.AddItemAsync(blogComment))
                    {
                        throw new Error(this.__ResStr("alreadyExists", "An error occurred adding this new comment"));
                    }

                    // send notification email
                    BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

                    if (config.NotifyNewComment)
                    {
                        SendEmail sendEmail = new SendEmail();
                        object    parms     = new {
                            Description = !blogComment.Approved ? this.__ResStr("needApproval", "This comment requires your approval.") : this.__ResStr("autoApproval", "This comment has been automatically approved."),
                            Category    = (await blogEntry.GetCategoryAsync()).ToString(),
                            Title       = blogEntry.Title.ToString(),
                            Url         = Manager.CurrentSite.MakeUrl(await BlogConfigData.GetEntryCanonicalNameAsync(blogEntry.Identity)),
                            Comment     = Utility.HtmlDecode(model.Comment),
                            UserName    = model.Name,
                            UserEmail   = model.Email,
                            UserWebsite = model.Website,
                        };
                        string subject = this.__ResStr("newComment", "New Blog Comment ({0} - {1})", blogEntry.Title.ToString(), Manager.CurrentSite.SiteDomain);
                        await sendEmail.PrepareEmailMessageAsync(config.NotifyEmail, subject, await sendEmail.GetEmailFileAsync(Package.GetCurrentPackage(this), "New Comment.txt"), Parameters : parms);

                        await sendEmail.SendAsync(true);
                    }

                    if (!blogComment.Approved)
                    {
                        return(FormProcessed(model, this.__ResStr("okSavedReview", "New comment saved - It will be reviewed before becoming publicly viewable"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage));
                    }
                    else
                    {
                        return(FormProcessed(model, this.__ResStr("okSaved", "New comment added"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> UsersAdd_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (UserDefinitionDataProvider dataProvider = new UserDefinitionDataProvider()) {
                LoginConfigData config = await LoginConfigDataProvider.GetConfigAsync();

                switch (config.RegistrationType)
                {
                default:
                case RegistrationTypeEnum.NameAndEmail: {     // Email == model.Email
                    List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                            Field = nameof(UserDefinition.Email), Operator = "==", Value = model.Email,
                        });
                    UserDefinition userExists = await dataProvider.GetItemAsync(filters);

                    if (userExists != null)
                    {
                        ModelState.AddModelError(nameof(model.Email), this.__ResStr("emailUsed", "An account using email address {0} already exists.", model.Email));
                        return(PartialView(model));
                    }
                    break;
                }

                case RegistrationTypeEnum.EmailOnly:
                    model.UserName = model.Email;
                    break;

                case RegistrationTypeEnum.NameOnly:
                    model.UserName = model.Email;
                    break;
                }

                UserDefinition user = model.GetData();

                string hashedNewPassword;
#if MVC6
                IPasswordHasher <UserDefinition> passwordHasher = (IPasswordHasher <UserDefinition>)YetaWFManager.ServiceProvider.GetService(typeof(IPasswordHasher <UserDefinition>));
                hashedNewPassword = passwordHasher.HashPassword(user, model.Password);
#else
                UserManager <UserDefinition> userManager = Managers.GetUserManager();
                hashedNewPassword = userManager.PasswordHasher.HashPassword(model.Password);
#endif
                user.PasswordPlainText = config.SavePlainTextPassword ? model.Password : null;
                user.PasswordHash      = hashedNewPassword;

                if (!await dataProvider.AddItemAsync(user))
                {
                    throw new Error(this.__ResStr("alreadyExists", "A user named \"{0}\" already exists."), model.UserName);
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New user saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 6
0
 public async Task <ActionResult> RolesAdd_Partial(AddModel model)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(model));
     }
     using (RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider()) {
         if (!await dataProvider.AddItemAsync(model.GetData()))
         {
             throw new Error(this.__ResStr("alreadyExists", "A role named \"{0}\" already exists."), model.Name);
         }
         return(FormProcessed(model, this.__ResStr("okSaved", "New role \"{0}\" saved", model.Name), OnPopupClose: OnPopupCloseEnum.ReloadModule));
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> EntryAdd_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    throw new Error(this.__ResStr("alreadyExists", "An error occurred adding this new blog entry"));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New blog entry saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> AddBlockedNumber_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (BlockedNumberDataProvider dataProvider = new BlockedNumberDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    ModelState.AddModelError("Name", this.__ResStr("alreadyExists", "Blocked number already exists"));
                    return(PartialView(model));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New blocked number saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> CategoryAdd_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    ModelState.AddModelError(nameof(model.Category), this.__ResStr("alreadyExists", "A blog category named \"{0}\" already exists.", model.Category));
                    return(PartialView(model));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New blog category saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> AddExtension_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (ExtensionEntryDataProvider dataProvider = new ExtensionEntryDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    ModelState.AddModelError(nameof(AddModel.Extension), this.__ResStr("dup", "An entry for extension {0} already exists", model.Extension));
                    return(PartialView(model));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New extension saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> AddHoliday_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (HolidayEntryDataProvider dataProvider = new HolidayEntryDataProvider()) {
                if (!await dataProvider.AddItemAsync(model.GetData()))
                {
                    ModelState.AddModelError(nameof(AddModel.HolidayDate), this.__ResStr("dup", "An entry for {0} already exists", Formatting.FormatDate(model.HolidayDate)));
                    return(PartialView(model));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New holiday saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> UnifiedSetAdd_Partial(AddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            using (UnifiedSetDataProvider unifiedSetDP = new UnifiedSetDataProvider()) {
                if (!await unifiedSetDP.AddItemAsync(model.GetData()))
                {
                    ModelState.AddModelError(nameof(model.Name), this.__ResStr("alreadyExists", "A Unified Page Set named \"{0}\" already exists", model.Name));
                    return(PartialView(model));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "New Unified Page Set saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }