コード例 #1
0
ファイル: Page_Context.cs プロジェクト: zhouyijiaren/CMS
        public virtual ActionResult ExecutePlugins()
        {
            // Execute plugins on page
            var page       = PageRequestContext.Page.AsActual();
            var httpMethod = this.ControllerContext.HttpContext.Request.HttpMethod.ToUpper();

            if (page.Plugins != null)
            {
                foreach (var plugin in page.Plugins)
                {
                    var result = ExecutePlugin(plugin, null, httpMethod);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.PageLayout))
            {
                // Execute plugins on Layout
                var layout = new Layout(this.PageRequestContext.Site, this.PageLayout).LastVersion().AsActual();
                if (layout != null && layout.Plugins != null)
                {
                    foreach (var plugin in layout.Plugins)
                    {
                        var result = ExecutePlugin(plugin, null, httpMethod);
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                }
            }


            // Execute plugins on views
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);

            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(PageRequestContext.Site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    if (view.Plugins != null)
                    {
                        var positionContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), GetPositionViewData(viewPosition.PagePositionId));

                        foreach (var plugin in view.Plugins)
                        {
                            var result = ExecutePlugin(plugin, positionContext, httpMethod);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
            return(null);
        }
コード例 #2
0
        public System.Web.Mvc.ActionResult HttpGet(Page_Context context, PagePositionContext positionContext)
        {
            _responseManager.SetHeader("SamplePlugin", "GET");

            //context.ControllerContext.Controller.ViewBag.ovos = "ovos";

            //context.ControllerContext.Controller.ControllerContext.
            
            return null;
        }
コード例 #3
0
ファイル: Page_Context.cs プロジェクト: Epitomy/CMS
        private ActionResult ExecutePlugin(string pluginType, PagePositionContext positionContext)
        {
            var type = Type.GetType(pluginType);

            if (type == null)
            {
                return(null);
            }
            var plugin = (IPagePlugin)Activator.CreateInstance(type);

            return(plugin.Execute(this, positionContext));
        }
コード例 #4
0
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            HttpRequestBase request = context.ControllerContext.HttpContext.Request;
            Controller controller = (Controller)context.ControllerContext.Controller;
            string username = request.Form["username"];
            string email = request.Form["email"];
            try
            {
                if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(email))
                {
                    controller.ViewData.ModelState.AddModelError("", "Username or Email is required.".Localize());
                    return null;
                }
                else if (controller.ViewData.ModelState.IsValid)
                {
                    var repository = Repository.Current;
                    var textFolder = new TextFolder(repository, "Members");
                    TextContent content = null;
                    if (!string.IsNullOrEmpty(username))
                    {
                        content = textFolder.CreateQuery().WhereEquals("UserName", username).FirstOrDefault();
                        email = content.Get<string>("Email");
                    }
                    else
                    {
                        content = textFolder.CreateQuery().WhereEquals("Email", email).FirstOrDefault();
                        username = content.Get<string>("UserName");
                    }
                    if (content != null)
                    {
                        string randomValue = Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(16);
                        ServiceFactory.TextContentManager.Update(textFolder, content.UUID, new string[] { "ForgotPWToken" }, new object[] { randomValue });

                        string link = new Uri(request.Url, string.Format("ResetPassword?UserName={0}&token={1}".RawLabel().ToString(), username, randomValue)).ToString();
                        string emailBody = "<b>{0}</b> <br/><br/> To change your password, click on the following link:<br/> <br/> <a href='{1}'>{1}</a> <br/>".RawLabel().ToString();
                        string subject = "Reset your password".RawLabel().ToString();
                        string body = string.Format(emailBody, username, link);
                        SendMail(email, subject, body, false);
                    }
                    else
                    {
                        controller.ViewData.ModelState.AddModelError("", "The user does not exists.".RawLabel().ToString());
                    }
                    controller.ViewBag.Message = "An email with instructions to choose a new password has been sent to you.".RawLabel().ToString();
                }
            }
            catch (Exception e)
            {
                controller.ViewData.ModelState.AddModelError("", e.Message);
            }

            return null;
        }
コード例 #5
0
 public System.Web.Mvc.ActionResult HttpGet(Page_Context context, PagePositionContext positionContext)
 {
     HttpRequestBase request = context.ControllerContext.HttpContext.Request;
     Controller controller = (Controller)context.ControllerContext.Controller;
     string username = request.Params["UserName"];
     string token = request.Params["token"];
     if (!ValidateMemberPasswordToken(username, token))
     {
         context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", "The password token is invalid.".Localize());
     }
     return null;
 }
コード例 #6
0
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            HttpRequestBase request = context.ControllerContext.HttpContext.Request;
            Controller controller = (Controller)context.ControllerContext.Controller;
            string username = request.Params["UserName"];
            string token = request.Params["token"];
            if (!ValidateMemberPasswordToken(username, token))
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", "The password token is invalid.".Localize());
                return null;
            }
            AntiForgery.Validate();

            var newPassword = request.Form["newpassword"];
            var confirmPassword = request.Form["confirmPassword"];
            if (newPassword != confirmPassword)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", "The passwords do not match.".RawLabel().ToString());
                return null;
            }
            try
            {
                var httpContext = context.ControllerContext.HttpContext;
                var repository = Repository.Current;
                var textFolder = new TextFolder(repository, "Members");
                var content = textFolder.CreateQuery().WhereEquals("UserName", username).FirstOrDefault();

                var passwordSalt = "";
                if (content["PasswordSalt"] == null)
                {
                    passwordSalt = MemberAuth.GenerateSalt();
                }
                else
                {
                    passwordSalt = content["PasswordSalt"].ToString();
                }

                newPassword = MemberAuth.EncryptPassword(newPassword, passwordSalt);

                ServiceFactory.TextContentManager.Update(textFolder, content.UUID,
                    new string[] { "Password", "ForgotPWToken", "PasswordSalt" }, new object[] { newPassword, "", passwordSalt });
                context.ControllerContext.Controller.ViewBag.Message = "The password has been changed.".Label();

                MemberAuth.SetAuthCookie(username, false);
                return new RedirectResult(context.Url.FrontUrl().PageUrl("Dashboard").ToString());
            }
            catch (Exception e)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", e.Message);
                Kooboo.HealthMonitoring.Log.LogException(e);
            }
            return null;
        }
コード例 #7
0
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            AntiForgery.Validate();

            try
            {
                var httpContext = context.ControllerContext.HttpContext;
                var repository = Repository.Current;
                var textFolder = new TextFolder(repository, "Members");
                var userContent = MemberAuth.GetMemberContent();

                var oldPassword = httpContext.Request.Form["OldPassword"];
                var newPassword = httpContext.Request.Form["NewPassword"];

                if (userContent["PasswordSalt"] != null)
                {
                    oldPassword = MemberAuth.EncryptPassword(oldPassword, userContent["PasswordSalt"].ToString());
                }
                if (userContent["password"].ToString() == oldPassword)
                {
                    var passwordSalt = "";
                    if (userContent["PasswordSalt"] == null)
                    {
                        passwordSalt = MemberAuth.GenerateSalt();
                    }
                    else
                    {
                        passwordSalt = userContent["PasswordSalt"].ToString();
                    }

                    newPassword = MemberAuth.EncryptPassword(newPassword, passwordSalt);

                    ServiceFactory.TextContentManager.Update(textFolder, userContent.UUID, new string[] { "Password", "PasswordSalt" }, new object[] { newPassword, passwordSalt });
                    context.ControllerContext.Controller.ViewBag.Message = "The password has been changed.".RawLabel().ToString();
                }
                else
                {
                    context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", "The old password is invalid.".RawLabel().ToString());
                }
            }
            catch (Exception e)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", e);
                Kooboo.HealthMonitoring.Log.LogException(e);
            }
            return null;
        }
コード例 #8
0
ファイル: SignInPlugin.cs プロジェクト: Qupy/Extensions
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            AntiForgery.Validate();

            try
            {
                var httpContext = context.ControllerContext.HttpContext;
                var repository = Repository.Current;
                var textFolder = new TextFolder(repository, "Members");

                string username = httpContext.Request.Form["username"];
                string password = httpContext.Request.Form["password"];

                var member = textFolder.CreateQuery().WhereEquals("UserName", username).FirstOrDefault();

                if (member != null)
                {
                    var encryptedPassword = password;
                    if (member["PasswordSalt"] != null)
                    {
                        var passwordSalt = member["PasswordSalt"].ToString();
                        encryptedPassword = MemberAuth.EncryptPassword(password, passwordSalt);
                    }
                    if (encryptedPassword == member["Password"].ToString())
                    {
                        var rememberme = httpContext.Request.Form["rememberMe"].Contains("true");
                        var returnUrl = httpContext.Request.QueryString["returnUrl"];
                        if (string.IsNullOrEmpty(returnUrl))
                        {
                            returnUrl = context.Url.FrontUrl().PageUrl("Dashboard").ToString();
                        }
                        MemberAuth.SetAuthCookie(username, rememberme);
                        return new RedirectResult(returnUrl);
                    }
                }
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", "Username or password is invalid".RawLabel().ToString());
                return null;

            }
            catch (Exception e)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", e);
                Kooboo.HealthMonitoring.Log.LogException(e);
            }
            return null;
        }
コード例 #9
0
ファイル: Page_Context.cs プロジェクト: zhouyijiaren/CMS
        private ActionResult ExecutePlugin(string pluginType, PagePositionContext positionContext, string httpMethod)
        {
            var type = Type.GetType(pluginType);

            if (type == null)
            {
                return(null);
            }
            ActionResult result           = null;
            var          plugin           = (ICommonPagePlugin)Kooboo.TypeActivator.CreateInstance(type);
            var          httpMethodPlugin = plugin as IHttpMethodPagePlugin;
            var          pagePlugin       = plugin as IPagePlugin;

            switch (httpMethod)
            {
            case "POST":
                if (httpMethodPlugin != null)
                {
                    result = httpMethodPlugin.HttpPost(this, positionContext);
                }
                if (result == null && pagePlugin != null)
                {
                    result = pagePlugin.Execute(this, positionContext);
                }
                break;

            case "GET":
                if (httpMethodPlugin != null)
                {
                    result = httpMethodPlugin.HttpGet(this, positionContext);
                }
                if (result == null && pagePlugin != null)
                {
                    result = pagePlugin.Execute(this, positionContext);
                }
                break;

            default:
                if (pagePlugin != null)
                {
                    result = pagePlugin.Execute(this, positionContext);
                }
                break;
            }
            return(result);
        }
コード例 #10
0
ファイル: Page_Context.cs プロジェクト: zhouyijiaren/CMS
        public virtual void ExecuteDataRules()
        {
            var pageViewData = ControllerContext.Controller.ViewData;

            var site = PageRequestContext.Site.AsActual();
            var page = PageRequestContext.Page.AsActual();

            var dataRuleContext = new DataRuleContext(PageRequestContext.Site, PageRequestContext.Page)
            {
                ValueProvider = PageRequestContext.GetValueProvider()
            };

            if (page.DataRules != null)
            {
                DataRuleExecutor.Execute(pageViewData, dataRuleContext, page.DataRules);
            }
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);

            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    var positionViewData = (ViewDataDictionary)GetPositionViewData(viewPosition.PagePositionId).Merge(pageViewData);
                    var viewDataContext  = new PagePositionContext(view, viewPosition.ToParameterDictionary(), positionViewData);
                    var dataRules        = view.DataRules;
                    if (dataRules != null)
                    {
                        var valueProvider = PageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(viewDataContext.Parameters));
                        dataRuleContext.ValueProvider = valueProvider;
                        DataRuleExecutor.Execute(positionViewData, dataRuleContext, dataRules);
                    }
                    if (positionViewData.Model == null)
                    {
                        positionViewData.Model = positionViewData.Values.FirstOrDefault();
                    }
                    SetPositionViewData(viewPosition.PagePositionId, positionViewData);
                }
            }
        }
コード例 #11
0
ファイル: RegisterPlugin.cs プロジェクト: Qupy/Extensions
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            AntiForgery.Validate();

            try
            {
                var httpContext = context.ControllerContext.HttpContext;
                var repository = Repository.Current;
                var textFolder = new TextFolder(repository, "Members");
                var values = new NameValueCollection(httpContext.Request.Form);
                values["Published"] = true.ToString();

                var member = textFolder.CreateQuery().WhereEquals("UserName", values["username"]).FirstOrDefault();
                if (member != null)
                {
                    context.ControllerContext.Controller.ViewData.ModelState.AddModelError("UserName", "The user already exists.".RawLabel().ToString());
                }
                else
                {
                    values["PasswordSalt"] = MemberAuth.GenerateSalt();
                    values["Password"] = MemberAuth.EncryptPassword(values["Password"], values["PasswordSalt"]);

                    var textContext = ServiceFactory.TextContentManager.Add(repository, textFolder, null, null,
                       values, httpContext.Request.Files, null, httpContext.User.Identity.Name);

                    MemberAuth.SetAuthCookie(textContext["UserName"].ToString(), false);

                    return new RedirectResult(context.Url.FrontUrl().PageUrl("Dashboard").ToString());
                }

            }
            catch (Exception e)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", e);
                Kooboo.HealthMonitoring.Log.LogException(e);
            }
            return null;
        }
コード例 #12
0
ファイル: ProfilePlugin.cs プロジェクト: Qupy/Extensions
        public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            AntiForgery.Validate();

            try
            {
                var httpContext = context.ControllerContext.HttpContext;
                var repository = Repository.Current;
                var textFolder = new TextFolder(repository, "Members");
                var userContent = MemberAuth.GetMemberContent();

                var email = httpContext.Request.Form["Email"];
                var language = httpContext.Request.Form["Language"];

                ServiceFactory.TextContentManager.Update(textFolder, userContent.UUID, new string[] { "Email", "Language" }, new object[] { email, language });
            }
            catch (Exception e)
            {
                context.ControllerContext.Controller.ViewData.ModelState.AddModelError("", e);
                Kooboo.HealthMonitoring.Log.LogException(e);
            }
            return null;
        }
コード例 #13
0
ファイル: ContentPlugin.cs プロジェクト: jason1234/CMS
 public ActionResult HttpGet(Page_Context context, PagePositionContext positionContext)
 {
     return null;
 }
コード例 #14
0
 public System.Web.Mvc.ActionResult HttpGet(Page_Context context, PagePositionContext positionContext)
 {
     return null;
 }
コード例 #15
0
ファイル: Page_Context.cs プロジェクト: ebojangi/CMS
 private ActionResult ExecutePlugin(string pluginType, PagePositionContext positionContext, string httpMethod)
 {
     var type = Type.GetType(pluginType);
     if (type == null)
     {
         return null;
     }
     ActionResult result = null;
     var plugin = (ICommonPagePlugin)Kooboo.TypeActivator.CreateInstance(type);
     var httpMethodPlugin = plugin as IHttpMethodPagePlugin;
     var pagePlugin = plugin as IPagePlugin;
     switch (httpMethod)
     {
         case "POST":
             if (httpMethodPlugin != null)
             {
                 result = httpMethodPlugin.HttpPost(this, positionContext);
             }
             if (result == null && pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
         case "GET":
             if (httpMethodPlugin != null)
             {
                 result = httpMethodPlugin.HttpGet(this, positionContext);
             }
             if (result == null && pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
         default:
             if (pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
     }
     return result;
 }
コード例 #16
0
ファイル: ContentPlugin.cs プロジェクト: jason1234/CMS
        public ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
        {
            var httpContext = context.ControllerContext.RequestContext.HttpContext;

            var site = context.PageRequestContext.Site;

            var repository = site.GetRepository();
            if (repository == null)
            {
                throw new SiteRepositoryNotExists();
            }
            object model = null;
            Exception exception = null;
            try
            {
                var folderName = context.ControllerContext.RequestContext.GetRequestValue("FolderName");
                if (!string.IsNullOrEmpty(folderName))
                {
                    var folder = FolderHelper.Parse<TextFolder>(repository, folderName);
                    model = DoPost(repository, folder, context.ControllerContext, context.ControllerContext.HttpContext.Request.Form);
                }
            }
            catch (Exception e)
            {
                exception = e;
            }

            return PluginHelper.ReturnActionResult(context.ControllerContext, model, exception);
        }
コード例 #17
0
ファイル: Page_Context.cs プロジェクト: ebojangi/CMS
        public virtual ActionResult ExecutePlugins()
        {
            // Execute plugins on page
            var page = PageRequestContext.Page.AsActual();
            var httpMethod = this.ControllerContext.HttpContext.Request.HttpMethod.ToUpper();
            if (page.Plugins != null)
            {
                foreach (var plugin in page.Plugins)
                {
                    var result = ExecutePlugin(plugin, null, httpMethod);
                    if (result != null)
                    {
                        return result;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.PageLayout))
            {
                // Execute plugins on Layout
                var layout = new Layout(this.PageRequestContext.Site, this.PageLayout).LastVersion().AsActual();
                if (layout != null && layout.Plugins != null)
                {
                    foreach (var plugin in layout.Plugins)
                    {
                        var result = ExecutePlugin(plugin, null, httpMethod);
                        if (result != null)
                        {
                            return result;
                        }
                    }
                }
            }

            // Execute plugins on views
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(PageRequestContext.Site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    if (view.Plugins != null)
                    {
                        var positionContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), GetPositionViewData(viewPosition.PagePositionId));

                        foreach (var plugin in view.Plugins)
                        {
                            var result = ExecutePlugin(plugin, positionContext, httpMethod);
                            if (result != null)
                            {
                                return result;
                            }
                        }
                    }
                }
            }
            return null;
        }
コード例 #18
0
ファイル: Page_Context.cs プロジェクト: ebojangi/CMS
        public virtual void ExecuteDataRules()
        {
            var pageViewData = ControllerContext.Controller.ViewData;

            var site = PageRequestContext.Site.AsActual();
            var page = PageRequestContext.Page.AsActual();

            var dataRuleContext = new DataRuleContext(PageRequestContext.Site, PageRequestContext.Page) { ValueProvider = PageRequestContext.GetValueProvider() };
            if (page.DataRules != null)
            {
                DataRuleExecutor.Execute(pageViewData, dataRuleContext, page.DataRules);
            }
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    var positionViewData = (ViewDataDictionary)GetPositionViewData(viewPosition.PagePositionId).Merge(pageViewData);
                    var viewDataContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), positionViewData);
                    var dataRules = view.DataRules;
                    if (dataRules != null)
                    {
                        var valueProvider = PageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(viewDataContext.Parameters));
                        dataRuleContext.ValueProvider = valueProvider;
                        DataRuleExecutor.Execute(positionViewData, dataRuleContext, dataRules);
                    }
                    if (positionViewData.Model == null)
                    {
                        positionViewData.Model = positionViewData.Values.FirstOrDefault();
                    }
                    SetPositionViewData(viewPosition.PagePositionId, positionViewData);
                }
            }
        }
コード例 #19
0
ファイル: PagePluginSample.cs プロジェクト: jason1234/CMS
 public System.Web.Mvc.ActionResult Execute(Page_Context pageViewContext, PagePositionContext positionContext)
 {
     //pageViewContext.ControllerContext.HttpContext.Response.Write("Sample plugin executed.<br/>");
     return null;
 }
コード例 #20
0
ファイル: PagePluginSample.cs プロジェクト: jason1234/CMS
 public System.Web.Mvc.ActionResult HttpPost(Page_Context context, PagePositionContext positionContext)
 {
     _responseManager.SetHeader("SamplePlugin", "POST");
     return null;
 }
コード例 #21
0
ファイル: Page_Context.cs プロジェクト: Epitomy/CMS
 private ActionResult ExecutePlugin(string pluginType, PagePositionContext positionContext)
 {
     var type = Type.GetType(pluginType);
     if (type == null)
     {
         return null;
     }
     var plugin = (IPagePlugin)Activator.CreateInstance(type);
     return plugin.Execute(this, positionContext);
 }