Пример #1
0
        public async Task <ActionResult> DisqusConfig()
        {
            using (DisqusConfigDataProvider dataProvider = new DisqusConfigDataProvider()) {
                Model model           = new Model {
                };
                DisqusConfigData data = await dataProvider.GetItemAsync();

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "The Disqus settings could not be found"));
                }
                model.SetData(data);
                return(View(model));
            }
        }
Пример #2
0
        public async Task <ActionResult> Disqus()
        {
            using (DisqusConfigDataProvider dataProvider = new DisqusConfigDataProvider()) {
                DisqusConfigData config = await dataProvider.GetItemAsync();

                if (config == null)
                {
                    throw new Error(this.__ResStr("notFound", "The Disqus settings could not be found"));
                }
                if (string.IsNullOrWhiteSpace(config.ShortName))
                {
                    throw new Error(this.__ResStr("notShortName", "The Disqus settings must be updated to define the site's Shortname"));
                }
                DisplayModel model = new DisplayModel {
                    ShortName = config.ShortName,
                };
                if (config.UseSSO &&
                    !string.IsNullOrWhiteSpace(config.PrivateKey) && !string.IsNullOrWhiteSpace(config.PublicKey) &&
                    !string.IsNullOrWhiteSpace(config.LoginUrl))
                {
                    model.UseSSO = true;
                    if (Manager.HaveUser)
                    {
                        model.PublicKey = config.PublicKey;
                        string avatarUrl = "";
                        if (config.AvatarType == DisqusConfigData.AvatarTypeEnum.Gravatar)
                        {
                            avatarUrl = "https:" + GravatarComponentBase.GravatarUrl(Manager.UserEmail, config.GravatarSize, config.GravatarRating, config.GravatarDefault);
                        }
                        SSO sso = new Support.SSO(config.PrivateKey);
                        model.AuthPayload = sso.GetPayload(Manager.UserId.ToString(), Manager.UserName, Manager.UserEmail, avatarUrl);
                    }
                    else
                    {
                        model.LoginUrl = Manager.CurrentSite.MakeUrl(config.LoginUrl);
                        model.Width    = config.Width;
                        model.Height   = config.Height;
                    }
                    string logoffUrl = WebConfigHelper.GetValue <string>("MvcApplication", "LogoffUrl", null, Package: false);
                    if (string.IsNullOrWhiteSpace(logoffUrl))
                    {
                        throw new InternalError("MvcApplication LogoffUrl not defined in web.cofig/appsettings.json - This is required to log off the current user");
                    }
                    model.LogoffUrl = Manager.CurrentSite.MakeUrl(logoffUrl + Manager.CurrentPage.EvaluatedCanonicalUrl);
                }
                return(View(model));
            }
        }
Пример #3
0
        public async Task <ActionResult> DisqusConfig_Partial(Model model)
        {
            using (DisqusConfigDataProvider dataProvider = new DisqusConfigDataProvider()) {
                DisqusConfigData data = await dataProvider.GetItemAsync();// get the original item

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display
                await dataProvider.UpdateConfigAsync(data);

                return(FormProcessed(model, this.__ResStr("okSaved", "Disqus settings saved"), NextPage: Manager.ReturnToUrl));
            }
        }
Пример #4
0
        public async Task <ActionResult> DisqusLinks(string disqus)
        {
            using (DisqusConfigDataProvider dataProvider = new DisqusConfigDataProvider()) {
                DisqusConfigData config = await dataProvider.GetItemAsync();

                if (config == null)
                {
                    return(new EmptyResult());
                }
                if (string.IsNullOrWhiteSpace(config.ShortName))
                {
                    return(new EmptyResult());
                }
                DisplayModel model = new DisplayModel {
                    ShortName = config.ShortName,
                };
                return(View(model));
            }
        }