コード例 #1
0
        public override void Execute()
        {
            WriteLiteral("Name: ");


            #line 4 "..\..\Views\ViewWithLink.cshtml"
            Write(Model.Name);


            #line default
            #line hidden
            WriteLiteral(" ");


            #line 4 "..\..\Views\ViewWithLink.cshtml"
            Write(Url.Content("some content"));


            #line default
            #line hidden
            WriteLiteral(", ");


            #line 4 "..\..\Views\ViewWithLink.cshtml"
            Write(Url.Absolute("~/images/logo.gif"));


            #line default
            #line hidden
        }
コード例 #2
0
        public virtual ActionResult BlogCategory(string slug, string parentSlug = null)
        {
            CategoryModel category;

            try
            {
                category = _blogRepository.GetCategory(slug);
            }
            catch (EntityNotFoundException)
            {
                // Throw a 404 if the category doesn't exist
                return(NotFound());
            }

            // If the category has a parent category, ensure it's in the URL
            if (category.Parent != null && string.IsNullOrEmpty(parentSlug))
            {
                return(RedirectToActionPermanent("BlogCategory", "Feed", new { slug, parentSlug = category.Parent.Slug }));
            }

            var posts = _blogRepository.LatestPosts(category, ITEMS_IN_FEED);

            return(RenderFeed(posts, new FeedViewModel
            {
                FeedGuidBase = "Category-" + category.Slug + "-",
                Title = category.Title + " - " + _siteConfig.BlogName,
                Description = category.Title + " posts to " + _siteConfig.BlogName,
                FeedUrl = Url.Absolute(Url.BlogCategoryFeed(category)),
                SiteUrl = Url.Absolute(Url.BlogCategory(category))
            }));
        }
コード例 #3
0
        /// <summary>
        /// Finds out if the user already exists in the database, if not then it gets created
        /// </summary>
        /// <returns></returns>
        internal async Task <bool> BuildWindowsUser()
        {
            CustomUser user = await UserManager.FindByNameAsync(windowsUserName);

            if ((user != null) && (!string.IsNullOrEmpty(user.Id)))
            {
                //user already exists
                if (!user.IsUserAutoGenerated)
                {
                    //weird circumstance.  existing user in the database was NOT auto created, but entered in explicitly.
                    throw new InvalidOperationException("User with login name " + windowsUserName + " exists, but not as a windows authorized user");
                }
                else
                {
#if !DEBUG
                    if (Request.IsSecureConnection)
                    {
#endif
                    string tokenURL = Url.Absolute(Url.Content("~/token"));
                    await TokenHolder.SetBearerTokenFromOAuth(tokenURL, user.UserName, windowsAuthPassword);

#if !DEBUG
                }
#endif
                    await SignInManager.SignInAsync(user, true, true);

                    return(true);
                }
            }
            else
            {
                //user does NOT exist in database, create user default details
                user = GetAutoCreateUser();
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    //not ideal.  we don't know the user ID, so we have to search the user manager again to make sure it got created
                    user = await UserManager.FindByNameAsync(user.UserName);

                    //add user role if we like
                    //await UserManager.AddToRoleAsync(user.Id, "WhateverRoleIsInYourDatabase");
                    return(await BuildWindowsUser());    //return back through the method, it should just pass through the 'does user exist' check this time without issue
                }
                else
                {
                    throw new InvalidOperationException(string.Join("|", result.Errors));
                }
            }
            //return false;
        }
コード例 #4
0
        public override void Execute()
        {
            #line 3 "..\..\Views\SimpleViewWithLayout.cshtml"

            Layout = "~/Views/Shared/_Layout.cshtml";


            #line default
            #line hidden
            WriteLiteral("\r\nIn Main View: ");


            #line 6 "..\..\Views\SimpleViewWithLayout.cshtml"
            Write(Model.Name);


            #line default
            #line hidden
            WriteLiteral("\r\nBefore Partial\r\n");


            #line 8 "..\..\Views\SimpleViewWithLayout.cshtml"
            Write(Html.Partial("SimplePartial", new { Name = "Partial" }));


            #line default
            #line hidden
            WriteLiteral("\r\nAfter Partial\r\nUrl: ");


            #line 10 "..\..\Views\SimpleViewWithLayout.cshtml"
            Write(Url.Content("~/images/logo.gif"));


            #line default
            #line hidden
            WriteLiteral("\r\nAbsolute Url: ");


            #line 11 "..\..\Views\SimpleViewWithLayout.cshtml"
            Write(Url.Absolute("~/images/logo.gif"));


            #line default
            #line hidden
        }
コード例 #5
0
        public async Task <ActionResult> LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
#if !DEBUG
                if (Request.IsSecureConnection)
                {
#endif
                //not required, but just an additional 'set' to give the user web api auth access
                string tokenURL = Url.Absolute(Url.Content("~/token"));
                await TokenHolder.SetBearerTokenFromOAuth(tokenURL, model.UserName, model.Password);

#if !DEBUG
            }
#endif

                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, change to shouldLockout: true
                var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

                switch (result)
                {
                case SignInStatus.Success:
                    ICustomUser usr = await UserManager.FindByNameAsync(model.UserName);

                    return(HandleAfterPasswordSuccess(usr, model, returnUrl));

                //case SignInStatus.LockedOut:
                //return View("Lockout");
                //case SignInStatus.RequiresVerification:   //this is for 2 factor validation
                //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
コード例 #6
0
        public FileResult SiteMap()
        {
            var        doc    = new XDocument();
            XNamespace ns     = "http://www.sitemaps.org/schemas/sitemap/0.9";
            var        urlset = new XElement(ns + "urlset");

            urlset.Add(new XElement(ns + "url",
                                    new XElement(ns + "loc", Url.Absolute(Url.Home().Index())),
                                    new XElement(ns + "priority", "1.0")));

            // TODO: Add in additional urls as needed

            doc.Add(urlset);

            using (var ms = new MemoryStream())
            {
                doc.Save(ms);

                return(File(ms.ToArray(), "text/xml"));
            }
        }
コード例 #7
0
        public override void Execute()
        {
            WriteLiteral("Super Funky Website\r\n--------------------------------------\r\n");


            #line 4 "..\..\Views\Shared\PlainTextLayout.cshtml"
            Write(RenderBody());


            #line default
            #line hidden
            WriteLiteral("\r\n--------------------------------------\r\nFooter:\r\nTerms and conditions: ");


            #line 7 "..\..\Views\Shared\PlainTextLayout.cshtml"
            Write(Url.Absolute("~/tnc"));


            #line default
            #line hidden
            WriteLiteral("\r\nUnsubscribe: ");


            #line 8 "..\..\Views\Shared\PlainTextLayout.cshtml"
            Write(Url.Absolute("~/unsubscribe"));


            #line default
            #line hidden
            WriteLiteral("\r\nEmail sent on ");


            #line 9 "..\..\Views\Shared\PlainTextLayout.cshtml"
            Write(DateTime.Now.ToString());


            #line default
            #line hidden
            WriteLiteral(" by Facepack\r\n");
        }
コード例 #8
0
        public override void Execute()
        {
            WriteLiteral("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xh" +
                         "tml1/DTD/xhtml1-strict.dtd\"> \n<html");

            WriteLiteral(" xmlns=\"http://www.w3.org/1999/xhtml\"");

            WriteLiteral(">\n<head>\n\t<meta");

            WriteLiteral(" http-equiv=\"Content-Type\"");

            WriteLiteral(" content=\"text/html; charset=utf-8\"");

            WriteLiteral(" />\n\t<meta");

            WriteLiteral(" name=\"viewport\"");

            WriteLiteral(" content=\"width=device-width, initial-scale=1.0\"");

            WriteLiteral("/>\n\t<title>Your Message Subject or Title</title>\n\t<style");

            WriteLiteral(" type=\"text/css\"");

            WriteLiteral(">\n\t\t/* Based on The MailChimp Reset INLINE: Yes. */  \n\t\t/* Client-specific Styles" +
                         " */\n\t\t#outlook a {padding:0;} /* Force Outlook to provide a \"view in browser\" me" +
                         "nu link. */\n\t\tbody{width:100% !important; -webkit-text-size-adjust:100%; -ms-tex" +
                         "t-size-adjust:100%; margin:0; padding:0;color:white} \n\t\t/* Prevent Webkit and Wi" +
                         "ndows Mobile platforms from changing default font sizes.*/ \n\t\t.ExternalClass {wi" +
                         "dth:100%;} /* Force Hotmail to display emails at full width */  \n\t\t.ExternalClas" +
                         "s, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td" +
                         ", .ExternalClass div {line-height: 100%;}\n\t\t/* Forces Hotmail to display normal " +
                         "line spacing.  More on that: http://www.emailonacid.com/forum/viewthread/43/ */ " +
                         "\n\t\t#backgroundTable {margin:0; padding:0; width:100% !important; line-height: 10" +
                         "0% !important;background-color:black}\n\t\t/* End reset */\n\n\t\t/* Some sensible defa" +
                         "ults for images\n\t\tBring inline: Yes. */\n\t\timg {outline:none; text-decoration:non" +
                         "e; -ms-interpolation-mode: bicubic;} \n\t\ta img {border:none;} \n\t\t.image_fix {disp" +
                         "lay:block;}\n\n\t\t/* Yahoo paragraph fix\n\t\tBring inline: Yes. */\n\t\tp {margin: 1em 0" +
                         ";}\n\n\t\t/* Hotmail header color reset\n\t\tBring inline: Yes. */\n\t\th1, h2, h3, h4, h5" +
                         ", h6 {color: black !important;}\n\n\t\th1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: bl" +
                         "ue !important;}\n\n\t\th1 a:active, h2 a:active,  h3 a:active, h4 a:active, h5 a:act" +
                         "ive, h6 a:active {\n\t\tcolor: red !important; /* Preferably not the same color as " +
                         "the normal header link color.  There is limited support for psuedo classes in em" +
                         "ail clients, this was added just for good measure. */\n\t\t}\n\n\t\th1 a:visited, h2 a:" +
                         "visited,  h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {\n\t\tcolor: purp" +
                         "le !important; /* Preferably not the same color as the normal header link color." +
                         " There is limited support for psuedo classes in email clients, this was added ju" +
                         "st for good measure. */\n\t\t}\n\n\t\t/* Outlook 07, 10 Padding issue fix\n\t\tBring inlin" +
                         "e: No.*/\n\t\ttable td {border-collapse: collapse;}\n\n\t\t/* Remove spacing around Out" +
                         "look 07, 10 tables\n\t\tBring inline: Yes */\n\t\ttable { border-collapse:collapse; ms" +
                         "o-table-lspace:0pt; mso-table-rspace:0pt; }\n\n\t\t/* Styling your links has become " +
                         "much simpler with the new Yahoo.  In fact, it falls in line with the main credo " +
                         "of styling in email and make sure to bring your styles inline.  Your link colors" +
                         " will be uniform across clients when brought inline.\n\t\tBring inline: Yes. */\n\t\ta" +
                         " {color: orange;}\n\n\n\t\t/***************************************************\n\t\t***" +
                         "*************************************************\n\t\tMOBILE TARGETING\n\t\t*********" +
                         "*******************************************\n\t\t**********************************" +
                         "*****************/\n\t\t");

            WriteLiteral(@"@media only screen and (max-device-width: 480px) {
			/* Part one of controlling phone number linking for mobile. */
			a[href^=""tel""], a[href^=""sms""] {
						text-decoration: none;
						color: blue; /* or whatever your want */
						pointer-events: none;
						cursor: default;
					}

			.mobile_link a[href^=""tel""], .mobile_link a[href^=""sms""] {
						text-decoration: default;
						color: orange !important;
						pointer-events: auto;
						cursor: default;
					}

		}

		/* More Specific Targeting */

		"        );

            WriteLiteral(@"@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
		/* You guessed it, ipad (tablets, smaller screens, etc) */
			/* repeating for the ipad */
			a[href^=""tel""], a[href^=""sms""] {
						text-decoration: none;
						color: blue; /* or whatever your want */
						pointer-events: none;
						cursor: default;
					}

			.mobile_link a[href^=""tel""], .mobile_link a[href^=""sms""] {
						text-decoration: default;
						color: orange !important;
						pointer-events: auto;
						cursor: default;
					}
		}

		"        );

            WriteLiteral("@media only screen and (-webkit-min-device-pixel-ratio: 2) {\n\t\t/* Put your iPhone" +
                         " 4g styles in here */ \n\t\t}\n\n\t\t/* Android targeting */\n\t\t");

            WriteLiteral("@media only screen and (-webkit-device-pixel-ratio:.75){\n\t\t/* Put CSS for low den" +
                         "sity (ldpi) Android layouts in here */\n\t\t}\n\t\t");

            WriteLiteral("@media only screen and (-webkit-device-pixel-ratio:1){\n\t\t/* Put CSS for medium de" +
                         "nsity (mdpi) Android layouts in here */\n\t\t}\n\t\t");

            WriteLiteral("@media only screen and (-webkit-device-pixel-ratio:1.5){\n\t\t/* Put CSS for high de" +
                         "nsity (hdpi) Android layouts in here */\n\t\t}\n\t\t/* end Android targeting */\n\n\t</st" +
                         "yle>\n\n\t<!-- Targeting Windows Mobile -->\n\t<!--[if IEMobile 7]>\n\t<style");

            WriteLiteral(" type=\"text/css\"");

            WriteLiteral(@">
	
	</style>
	<![endif]-->   

	<!-- ***********************************************
	****************************************************
	END MOBILE TARGETING
	****************************************************
	************************************************ -->

	<!--[if gte mso 9]>
		<style>
		/* Target Outlook 2007 and 2010 */
		</style>
	<![endif]-->
</head>
<body>
<!-- Wrapper/Container Table: Use a wrapper table to control the width and the background color consistently of your email. Use this approach instead of setting attributes on the body tag. -->
    <table");

            WriteLiteral(" cellpadding=\"0\"");

            WriteLiteral(" cellspacing=\"0\"");

            WriteLiteral(" border=\"0\"");

            WriteLiteral(" id=\"backgroundTable\"");

            WriteLiteral(">\r\n        <tr>\r\n            <td>Header: My Funky Website!</td>\r\n        </tr>\n  " +
                         "      <tr>\n            <td");

            WriteLiteral(" valign=\"top\"");

            WriteLiteral("> \n");

            WriteLiteral("                ");


            #line 145 "..\..\Views\Shared\HtmlLayout.cshtml"
            Write(RenderBody());


            #line default
            #line hidden
            WriteLiteral("\n            </td>\n        </tr>\n        <tr>\r\n            <td><p>Footer: <a");

            WriteAttribute("href", Tuple.Create(" href=\"", 5636), Tuple.Create("\"", 5665)

            #line 149 "..\..\Views\Shared\HtmlLayout.cshtml"
                           , Tuple.Create(Tuple.Create("", 5643), Tuple.Create <System.Object, System.Int32>(Url.Absolute("~/tnc")

            #line default
            #line hidden
                                                                                                             , 5643), false)
                           );

            WriteLiteral(">terms and conditions</a> - <a");

            WriteAttribute("href", Tuple.Create(" href=\"", 5696), Tuple.Create("\"", 5733)

            #line 149 "..\..\Views\Shared\HtmlLayout.cshtml"
                           , Tuple.Create(Tuple.Create("", 5703), Tuple.Create <System.Object, System.Int32>(Url.Absolute("~/unsubscribe")

            #line default
            #line hidden
                                                                                                             , 5703), false)
                           );

            WriteLiteral(">unsubscribe</a> - etc</p></td>\r\n        </tr>\n        <tr>\r\n            <td>Emai" +
                         "l HTML based on <a");

            WriteLiteral(" href=\"http://htmlemailboilerplate.com\"");

            WriteLiteral(" target =\"_blank\" style=\"color: orange; text-decoration: none;\">http://htmlemailb" +
                         "oilerplate.com</a>\n            </td>\r\n        </tr>\n    </table>  \n<!-- End of w" +
                         "rapper table -->\n</body>\n</html>\n");
        }
コード例 #9
0
        public ActionResult Analytics(int?duration)
        {
            CacheContext.InvalidateOn(TriggerFrom.Any <SiteSettings>());

            var settings = _siteSettingsService.GetSettings();

            if (string.IsNullOrEmpty(settings.AnalyticsToken))
            {
                const string scope = "https://www.google.com/analytics/feeds/";
                var          next  = Url.Absolute(Url.AnalyticsWidget().AuthResponse());
                var          auth  = new Authorize
                {
                    Url = AuthSubUtil.getRequestUrl(next, scope, false, true)
                };
                return(View("AnalyticsAuthorize", auth));
            }

            if (string.IsNullOrEmpty(settings.AnalyticsProfileId))
            {
                var config = new Config
                {
                    Accounts = GetAccounts(settings),
                    Profiles = GetProfiles(settings)
                };

                return(View("AnalyticsConfig", config));
            }

            duration = duration ?? 30;
            var model = new ViewModels.Widgets.Analytics
            {
                Duration     = duration.Value,
                Start        = DateTime.Today.AddDays(-1 * duration.Value),
                End          = DateTime.Now,
                Visits       = new Dictionary <DateTime, int>(),
                PageViews    = new Dictionary <string, int>(),
                PageTitles   = new Dictionary <string, string>(),
                TopReferrers = new Dictionary <string, int>(),
                TopSearches  = new Dictionary <string, int>()
            };

            if (model.Start > model.End)
            {
                var tempDate = model.Start;
                model.Start = model.End;
                model.End   = tempDate;
            }

            var profiles = GetProfiles(settings);
            var profile  = profiles.SingleOrDefault(x => x.Id == settings.AnalyticsProfileId);

            if (profile == null)
            {
                throw new Exception("Unable to find the specified analytics profile: " + settings.AnalyticsProfileId);
            }
            model.Profile = profile;

            var authFactory = new GAuthSubRequestFactory("analytics", "MvcKickstart")
            {
                Token = settings.AnalyticsToken
            };

            var analytics = new AnalyticsService(authFactory.ApplicationName)
            {
                RequestFactory = authFactory
            };

            var profileId = "ga:" + settings.AnalyticsProfileId;

            // Get from All Visits
            var visits = new DataQuery(profileId, model.Start, model.End)
            {
                Metrics    = "ga:visits",
                Dimensions = "ga:date",
                Sort       = "ga:date"
            };
            var count = 0;

            foreach (DataEntry entry in analytics.Query(visits).Entries)
            {
                var value = entry.Metrics.First().IntegerValue;

                model.Visits.Add(model.Start.AddDays(count++), value);
            }

            // Get Site Usage
            var siteUsage = new DataQuery(profileId, model.Start, model.End)
            {
                Metrics = "ga:visits,ga:pageviews,ga:percentNewVisits,ga:avgTimeOnSite,ga:entranceBounceRate,ga:exitRate,ga:pageviewsPerVisit,ga:avgPageLoadTime"
            };
            var siteUsageResult = (DataEntry)analytics.Query(siteUsage).Entries.FirstOrDefault();

            if (siteUsageResult != null)
            {
                foreach (var metric in siteUsageResult.Metrics)
                {
                    switch (metric.Name)
                    {
                    case "ga:visits":
                        model.TotalVisits = metric.IntegerValue;
                        break;

                    case "ga:pageviews":
                        model.TotalPageViews = metric.IntegerValue;
                        break;

                    case "ga:percentNewVisits":
                        model.PercentNewVisits = metric.FloatValue;
                        break;

                    case "ga:avgTimeOnSite":
                        model.AverageTimeOnSite = TimeSpan.FromSeconds(metric.FloatValue);
                        break;

                    case "ga:entranceBounceRate":
                        model.EntranceBounceRate = metric.FloatValue;
                        break;

                    case "ga:exitRate":
                        model.PercentExitRate = metric.FloatValue;
                        break;

                    case "ga:pageviewsPerVisit":
                        model.PageviewsPerVisit = metric.FloatValue;
                        break;

                    case "ga:avgPageLoadTime":
                        model.AveragePageLoadTime = TimeSpan.FromSeconds(metric.FloatValue);
                        break;
                    }
                }
            }

            // Get Top Pages
            var topPages = new DataQuery(profileId, model.Start, model.End)
            {
                Metrics          = "ga:pageviews",
                Dimensions       = "ga:pagePath,ga:pageTitle",
                Sort             = "-ga:pageviews",
                NumberToRetrieve = 20
            };

            foreach (DataEntry entry in analytics.Query(topPages).Entries)
            {
                var value = entry.Metrics.First().IntegerValue;
                var url   = entry.Dimensions.Single(x => x.Name == "ga:pagePath").Value.ToLowerInvariant();
                var title = entry.Dimensions.Single(x => x.Name == "ga:pageTitle").Value;

                if (!model.PageViews.ContainsKey(url))
                {
                    model.PageViews.Add(url, 0);
                }
                model.PageViews[url] += value;

                if (!model.PageTitles.ContainsKey(url))
                {
                    model.PageTitles.Add(url, title);
                }
            }

            // Get Top Referrers
            var topReferrers = new DataQuery(profileId, model.Start, model.End)
            {
                Metrics          = "ga:visits",
                Dimensions       = "ga:source,ga:medium",
                Sort             = "-ga:visits",
                Filters          = "ga:medium==referral",
                NumberToRetrieve = 5
            };

            foreach (DataEntry entry in analytics.Query(topReferrers).Entries)
            {
                var visitCount = entry.Metrics.First().IntegerValue;
                var source     = entry.Dimensions.Single(x => x.Name == "ga:source").Value.ToLowerInvariant();

                model.TopReferrers.Add(source, visitCount);
            }

            // Get Top Searches
            var topSearches = new DataQuery(profileId, model.Start, model.End)
            {
                Metrics          = "ga:visits",
                Dimensions       = "ga:keyword",
                Sort             = "-ga:visits",
                Filters          = "ga:keyword!=(not set);ga:keyword!=(not provided)",
                NumberToRetrieve = 5
            };

            foreach (DataEntry entry in analytics.Query(topSearches).Entries)
            {
                var visitCount = entry.Metrics.First().IntegerValue;
                var source     = entry.Dimensions.Single(x => x.Name == "ga:keyword").Value.ToLowerInvariant();

                model.TopSearches.Add(source, visitCount);
            }

            return(View(model));
        }