/// <summary>
        /// Gets Web Settings
        /// </summary>
        static IWebSettings GetWebSettings()
        {
            var kernel      = KernelPersister.Get();
            var webSettings = kernel.GetService(typeof(IWebSettings)) as IWebSettings;

            return(webSettings);
        }
Esempio n. 2
0
        /// <summary>
        /// Fires on Begin Request
        /// </summary>
        protected void Application_BeginRequest()
        {
            var context = HttpContext.Current;
            Uri url     = context.Request.Url;

            if (WwwRegex.IsMatch(url.ToString()))
            {
                String newUrl = WwwRegex.Replace(url.ToString(), String.Format("{0}://", url.Scheme));
                context.Response.RedirectPermanent(newUrl);
            }

            // Handle Partner Detection
            if (!string.IsNullOrWhiteSpace(context.Request.QueryString["pid"]))
            {
                var kernel            = KernelPersister.Get();
                var partnerService    = kernel.Get <IPartnerService>();
                var partnerIdResolver = kernel.Get <IPartnerIdResolver>();

                var token     = context.Request.QueryString["pid"];
                var partnerId = partnerService.GetPartnerIdFromToken(token);

                if (partnerId != null)
                {
                    // Persist the Partner Id
                    partnerIdResolver.Persist(partnerId.Value);

                    // Redirect (to remove the url token)
                    context.Response.RedirectPermanent(url.ToString().ToLower().Replace("pid=" + token, "").TrimEnd(new[] { '?', '#' }), true);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// ctor the Mighty
        /// </summary>
        protected BrewgrController()
        {
            // Setup Messaging
            this.ViewBag.Messages      = new List <IMessage>();
            this.ForwardedMessageStore = new TempDataMessageStore(this.TempData);

            // Set Environment
            ViewBag.Environment = ConfigurationManager.AppSettings["Environment"];

            // Dependencies (manual injection to avoid ctor pollution)
            var kernel = KernelPersister.Get();

            this.UserResolver          = kernel.GetService(typeof(IUserResolver)) as IUserResolver;
            this.UserService           = kernel.GetService(typeof(IUserService)) as IUserService;
            this.WebSettings           = kernel.GetService(typeof(IWebSettings)) as IWebSettings;
            this.AuthenticationService = kernel.GetService(typeof(IAuthenticationService)) as IAuthenticationService;
        }
Esempio n. 4
0
        /// <summary>
        /// Fires on Begin Request
        /// </summary>
        protected void Application_BeginRequest()
        {
            var context = HttpContext.Current;
            Uri url     = context.Request.Url;

            if (WwwRegex.IsMatch(url.ToString()))
            {
                String newUrl = WwwRegex.Replace(url.ToString(), String.Format("{0}://", url.Scheme));
                context.Response.RedirectPermanent(newUrl);
            }

            if (!Context.Request.IsSecureConnection)
            {
                // This is an insecure connection, so redirect to the secure version
                UriBuilder uri = new UriBuilder(Context.Request.Url);
                if (!uri.Host.Equals("localhost") && !url.Host.Contains("dev.brewgr.com"))
                {
                    uri.Port   = 443;
                    uri.Scheme = "https";
                    Response.Redirect(uri.ToString());
                }
            }

            // Handle Partner Detection
            if (!string.IsNullOrWhiteSpace(context.Request.QueryString["pid"]))
            {
                var kernel            = KernelPersister.Get();
                var partnerService    = kernel.Get <IPartnerService>();
                var partnerIdResolver = kernel.Get <IPartnerIdResolver>();

                var token     = context.Request.QueryString["pid"];
                var partnerId = partnerService.GetPartnerIdFromToken(token);

                if (partnerId != null)
                {
                    // Persist the Partner Id
                    partnerIdResolver.Persist(partnerId.Value);

                    // Redirect (to remove the url token)
                    context.Response.RedirectPermanent(url.ToString().ToLower().Replace("pid=" + token, "").TrimEnd(new[] { '?', '#' }), true);
                }
            }
        }
        /// <summary>
        /// Makes a Notification
        /// </summary>
        public INotification Make(NotificationType notificationType)
        {
            var kernel = KernelPersister.Get();

            switch (notificationType)
            {
            case NotificationType.RecipeComment:
                return(kernel.GetService(typeof(RecipeCommentNotification)) as RecipeCommentNotification);

            case NotificationType.BrewerFollowed:
                return(kernel.GetService(typeof(BrewerFollowNotification)) as BrewerFollowNotification);

            case NotificationType.BrewSessionComment:
                return(kernel.GetService(typeof(BrewSessionCommentNotification)) as BrewSessionCommentNotification);

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Fires on Authorization
        /// </summary>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (filterContext.HttpContext != null)
            {
                var kernel   = KernelPersister.Get();
                var settings = kernel.GetService(typeof(IWebSettings)) as IWebSettings;

                // Disable RequireHttps if not PROD
                if (!(settings is ProdWebSettings))
                {
                    return;
                }
            }

            base.OnAuthorization(filterContext);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                RegisterServices(kernel);

                KernelPersister.Set(kernel);

                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Gets a Content Service
 /// </summary>
 static IContentService GetContentService()
 {
     return(KernelPersister.Get().Get <IContentService>());
 }