/// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static bool Impl(IRequireAuthentication handler, IContext context)
        {
            var authenticationProvider = SimpleWeb.Configuration.AuthenticationProvider ?? new DefaultAuthenticationProvider();
            var user = authenticationProvider.GetLoggedInUser(context);
            if (user == null || !user.IsAuthenticated)
            {
                if (SimpleWeb.Configuration.LoginPage != null)
                {
                    var uriTemplateAttribute = UriTemplateAttribute.Get(SimpleWeb.Configuration.LoginPage).FirstOrDefault();
                    if (uriTemplateAttribute != null)
                    {
                        context.Response.SetHeader("Location",
                                                     uriTemplateAttribute.Template + "?returnUrl=" +
                                                     Uri.EscapeDataString(context.Request.Url.ToString()));
                        context.Response.SetStatus(Status.TemporaryRedirect);
                        return false;
                    }
                }
                context.Response.StatusCode = 401;
                context.Response.StatusDescription = "Unauthorized";
                return false;
            }

            handler.CurrentUser = user;
            return true;
        }
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if the user is authenticated; otherwise, <c>false</c>.</returns>
        public static bool Impl(IRequireAuthentication handler, IContext context)
        {
            var authenticationProvider = SimpleWeb.Configuration.AuthenticationProvider ?? new DefaultAuthenticationProvider();
            var user = authenticationProvider.GetLoggedInUser(context);

            if (user == null || !user.IsAuthenticated)
            {
                if (SimpleWeb.Configuration.LoginPage != null)
                {
                    var uriTemplateAttribute = UriTemplateAttribute.Get(SimpleWeb.Configuration.LoginPage).FirstOrDefault();
                    if (uriTemplateAttribute != null)
                    {
                        var redirect = uriTemplateAttribute.Template + "?returnUrl=" + Uri.EscapeDataString(context.Request.Url.ToString());
                        context.Response.SetHeader("Location", redirect);
                        context.Response.Status = Status.TemporaryRedirect(redirect);
                        return(false);
                    }
                }
                context.Response.Status = "401 Unauthorized";
                return(false);
            }

            handler.CurrentUser = user;
            return(true);
        }
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if the user is authenticated; otherwise, <c>false</c>.</returns>
        public static bool Impl(IRequireAuthentication handler, IContext context)
        {
            var authenticationProvider = SimpleWeb.Configuration.AuthenticationProvider ?? new DefaultAuthenticationProvider();
            var user = authenticationProvider.GetLoggedInUser(context);
            if (user == null || !user.IsAuthenticated)
            {
                Redirect(context);
                return false;
            }

            handler.CurrentUser = user;
            return true;
        }
示例#4
0
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if the user is authenticated; otherwise, <c>false</c>.</returns>
        public static bool Impl(IRequireAuthentication handler, IContext context)
        {
            var authenticationProvider = SimpleWeb.Configuration.AuthenticationProvider ?? new DefaultAuthenticationProvider();
            var user = authenticationProvider.GetLoggedInUser(context);

            if (user == null || !user.IsAuthenticated)
            {
                Redirect(context);
                return(false);
            }

            handler.CurrentUser = user;
            return(true);
        }
 public static bool Impl(IRequireAuthentication e, IContext c)
 {
     Assert.NotNull(e);
     Assert.NotNull(c);
     return Called = true;
 }
 public static bool Impl(IRequireAuthentication e, IContext c)
 {
     Assert.NotNull(e);
     Assert.NotNull(c);
     return(Called = true);
 }