Exemple #1
0
        //private static Uri GetBaseUri_(HttpRequest request)
        //{
        //    // http://msdn.microsoft.com/en-us/library/system.web.httpruntime.appdomainappvirtualpath(v=vs.110).aspx
        //    // http://weblog.west-wind.com/posts/2009/Dec/21/Making-Sense-of-ASPNET-Paths

        //    string authority = request.Url.GetLeftPart(UriPartial.Authority);
        //    var uriBuilder = new UriBuilder(authority);
        //    uriBuilder.Path = request.ApplicationPath;
        //    return uriBuilder.Uri;

        //    // return VirtualPathUtility.ToAbsolute("~/") -> "/";
        //    // return uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
        //    // return uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);
        //}

        private static ChiffonLanguage?GetLanguageFromQueryString_(HttpRequest request)
        {
            Contract.Requires(request != null);

            return((from _ in request.QueryString.MayGetSingle("lang")
                    select ParseTo.Enum <ChiffonLanguage>(_)).ToNullable());
        }
        protected override void InitializeCustom(NameValueCollection config)
        {
            _baseUri = config.MayGetSingle(BASE_URI_KEY)
                       .Bind(val => ParseTo.Uri(val, UriKind.Absolute))
                       .ValueOrThrow(() => new ProviderException(Strings.RemoteAssetProvider_MissingOrInvalidBaseUri));

            config.Remove(BASE_URI_KEY);
        }
Exemple #3
0
        protected override Maybe <Maybe <Uri> > BindCore(HttpRequest request)
        {
            var targetUrl = request.QueryString
                            .MayGetSingle(Constants.SiteMap.TargetUrl)
                            .Bind(_ => ParseTo.Uri(_, UriKind.Relative));

            return(Maybe.Of(targetUrl));
        }
        private bool ValidateHttpMethod(HttpRequest request)
        {
            Debug.Assert(request != null);

            bool?q = from x in ParseTo.Enum <HttpVerbs>(request.HttpMethod)
                     select AcceptedVerbs.Contains(x);

            return(q ?? false);
        }
Exemple #5
0
        public ActionResult Register(RegisterViewModel model)
        {
            Require.NotNull(model, "model");

            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToHome());
            }

            // Ontologie.
            Ontology.Title       = Strings.Account_Register_Title;
            Ontology.Description = Strings.Account_Register_Description;
            Ontology.Relationships.CanonicalUrl = SiteMap.Register();

            // LayoutViewModel.
            LayoutViewModel.AddAlternateUrls(Environment.Language, _ => _.Register());
            LayoutViewModel.MainMenuCssClass = "register";
            LayoutViewModel.MainHeading      = Strings.Account_Register_MainHeading;

            if (!ModelState.IsValid)
            {
                return(View(Constants.ViewName.Account.Register, model));
            }

            _memberService.MemberCreated += (sender, e) =>
            {
                new AuthenticationService(HttpContext).SignIn(e.Member);
            };

            var result = _memberService.RegisterMember(new RegisterMemberRequest {
                CompanyName       = model.CompanyName,
                Email             = model.Email,
                FirstName         = model.FirstName,
                LastName          = model.LastName,
                NewsletterChecked = IsCheckBoxOn_(model.Newsletter),
            });

            if (result.IsBreak)
            {
                return(View(
                           Constants.ViewName.Account.RegisterFailure,
                           new RegisterFailureViewModel {
                    Message = result.Reason
                }));
            }

            string returnUrl = (from _ in ParseTo.Uri(model.ReturnUrl, UriKind.Relative) select _.ToString())
                               .ValueOrElse(String.Empty);

            return(RedirectToRoute(Constants.RouteName.Account.RegisterSuccess, new { returnUrl = returnUrl }));
        }
        private void Initialize_(NameValueCollection source)
        {
            Contract.Requires(source != null);

            // > Paramètres obligatoires <

            LogProfile = source.MayGetSingle("chiffon:LogProfile")
                         .ValueOrThrow(() => new ConfigurationErrorsException(
                                           "Missing or invalid config 'chiffon:LogProfile'."));

            LogMinimumLevel = (from _ in source.MayGetSingle("chiffon:LogMinimumLevel")
                               select ParseTo.Enum <LogEventLevel>(_))
                              .UnpackOrThrow(
                () => new ConfigurationErrorsException("Missing or invalid config 'chiffon:LogMinimumLevel'."));

            // TODO: validate this? Absolute and well-formed.
            PatternDirectory = source.MayGetSingle("chiffon:PatternDirectory")
                               .ValueOrThrow(() => new ConfigurationErrorsException(
                                                 "Missing or invalid config 'chiffon:PatternDirectory'."));

            // > Paramètres optionels <

            var version = s_AssemblyVersion.Major.ToString(CultureInfo.InvariantCulture)
                          + "." + s_AssemblyVersion.Minor.ToString(CultureInfo.InvariantCulture)
                          + "." + s_AssemblyVersion.Build.ToString(CultureInfo.InvariantCulture);

            CssVersion = source.MayGetSingle("chiffon:CssVersion").ValueOrElse(version);

            JavaScriptVersion = source.MayGetSingle("chiffon:JavaScriptVersion").ValueOrElse(version);

            DebugStyleSheet = (from _ in source.MayGetSingle("chiffon:DebugStyleSheet")
                               select ParseTo.Boolean(_))
                              .UnpackOrElse(DEFAULT_DEBUG_STYLESHEET);

            DebugJavaScript = (from _ in source.MayGetSingle("chiffon:DebugJavaScript")
                               select ParseTo.Boolean(_))
                              .UnpackOrElse(DEFAULT_DEBUG_JAVASCRIPT);

            EnableClientCache = (from _ in source.MayGetSingle("chiffon:EnableClientCache")
                                 select ParseTo.Boolean(_))
                                .UnpackOrElse(DEFAULT_ENABLE_CLIENT_CACHE);

            EnableServerCache = (from _ in source.MayGetSingle("chiffon:EnableServerCache")
                                 select ParseTo.Boolean(_))
                                .UnpackOrElse(DEFAULT_ENABLE_SERVER_CACHE);

            GoogleAnalyticsKey = source.MayGetSingle("chiffon:GoogleAnalyticsKey").ValueOrElse(s_DefaultGoogleAnalyticsKey);
        }
        protected override Maybe <PatternImageQuery> BindCore(HttpRequest request)
        {
            var nvc = request.QueryString;

            return
                (from designerKey in
                 Maybe.Flatten(nvc.MayGetSingle("designerKey").Select(_ => DesignerKey.MayParse(_)))
                 from reference in nvc.MayGetSingle("reference")
                 from size in
                 (from _ in nvc.MayGetSingle("size") select ParseTo.Enum <PatternImageSize>(_))
                 let variant = nvc.MayGetSingle("variant")
                               where size.HasValue
                               select new PatternImageQuery {
                DesignerKey = designerKey,
                Reference = reference,
                Size = size.Value,
                Variant = variant.ValueOrElse(String.Empty),
            });
        }
Exemple #8
0
        public ActionResult RegisterSuccess(string returnUrl)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(Constants.RouteName.Account.Register));
            }

            string nextUrl = (from _ in ParseTo.Uri(returnUrl, UriKind.Relative) select _.ToString())
                             .ValueOrElse(Url.RouteUrl(Constants.RouteName.Home.Index));

            // LayoutViewModel.
            LayoutViewModel.AddAlternateUrls(Environment.Language, _ => _.Register());
            LayoutViewModel.MainHeading      = Strings.Account_RegisterSuccess_MainHeading;
            LayoutViewModel.MainMenuCssClass = "register";

            return(View(Constants.ViewName.Account.RegisterSuccess, new RegisterSuccessViewModel {
                NextUrl = nextUrl
            }));
        }
Exemple #9
0
        public override void PreprocessDirective(string directiveName, IDictionary attributes)
        {
            Require.NotNull(attributes, nameof(attributes));

            // NB: Si rien n'est précisé, on considère que le filtre est actif localement.
            bool enabled = true;

            if (attributes.Contains(DIRECTIVE_NAME))
            {
                enabled = ParseTo.Boolean((string)attributes[DIRECTIVE_NAME], BooleanStyles.Literal) ?? enabled;

                // On supprime la directive afin de ne pas perturber le fonctionnement de ASP.NET.
                attributes.Remove(DIRECTIVE_NAME);
            }

            var section = NarvaloWebConfigurationManager.OptimizationSection;

            // Si le filtre est activé globalement (valeur par défaut), on vérifie la directive locale, sinon on
            // considère que le filtre ne doit pas être utilisé quelque soit la directive locale.
            Enabled = section.EnableWhiteSpaceBusting && enabled;

            base.PreprocessDirective(directiveName, attributes);
        }
        protected override Maybe <LogOnQuery> BindCore(HttpRequest request)
        {
            var form = request.Form;

            return
                (from email in form.MayGetSingle("email")
                 from password in form.MayGetSingle("password")
                 let targetUrl = form.MayGetSingle(Constants.SiteMap.TargetUrl).Bind(_ => ParseTo.Uri(_, UriKind.Relative))
                                 select new LogOnQuery {
                Email = email,
                Password = password,
                TargetUrl = targetUrl
            });
        }