public IHandlerBuilder?Activate([FromPath] int id, IRequest request)
        {
            var user = AccessControl.GetAccount(request);

            if (!user.Admin)
            {
                throw new ProviderException(ResponseStatus.Forbidden, "Your are not allowed to activate this user.");
            }

            using var context = Database.Create();

            var account = context.Accounts
                          .Where(c => c.ID == id)
                          .FirstOrDefault();

            if (account == null)
            {
                return(null);
            }

            account.Active = true;

            context.SaveChanges();

            return(Redirect.To($"{{controller}}/details/{id}/", true));
        }
Ejemplo n.º 2
0
        public void Redirect_to_destination()
        {
            var destination = new Input1();

            Redirect <StubRedirectable> .To(destination)
            .RedirectTo.AssertWasRedirectedTo(destination);
        }
Ejemplo n.º 3
0
        public IResponse?Handle(IRequest request)
        {
            var current = request.Target.Current;

            if (current != null)
            {
                if (Handlers.ContainsKey(current))
                {
                    request.Target.Advance();
                    return(Handlers[current].Handle(request));
                }
            }
            else
            {
                // force a trailing slash to prevent duplicate content
                if (!request.Target.Path.TrailingSlash)
                {
                    return(Redirect.To($"{request.Target.Path}/")
                           .Build(this)
                           .Handle(request));
                }

                if (Index != null)
                {
                    return(Index.Handle(request));
                }
            }

            if (Fallback != null)
            {
                return(Fallback.Handle(request));
            }

            return(null);
        }
        public IHandlerBuilder?Edit([FromPath] int number, Customer customer)
        {
            using var context = Database.Create();

            var existing = context.Customers
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (existing == null)
            {
                return(null);
            }

            existing.Number = customer.Number;

            existing.Name       = customer.Name.Trim();
            existing.FirstName  = OrNull(customer.FirstName);
            existing.Salutation = customer.Salutation;
            existing.Title      = OrNull(customer.Title);
            existing.Phone      = OrNull(customer.Phone);
            existing.Mail       = OrNull(customer.Mail);
            existing.Street     = OrNull(customer.Street);
            existing.Zip        = OrNull(customer.Zip);
            existing.City       = OrNull(customer.City);
            existing.Notes      = OrNull(customer.Notes);

            existing.Modified = DateTime.UtcNow;

            context.SaveChanges();

            return(Redirect.To($"{{controller}}/details/{customer.Number}/", true));
        }
Ejemplo n.º 5
0
        public void TestSimpleRelativeRoute()
        {
            var layout = Layout.Create()
                         .Add("redirect", Redirect.To("./me/to"));

            using var runner = TestRunner.Run(layout);

            using var response = runner.GetResponse("/redirect/");

            Assert.Equal("/redirect/me/to", new Uri(response.Headers["Location"]).AbsolutePath);
        }
Ejemplo n.º 6
0
        public void TestTemporary()
        {
            var redirect = Redirect.To("https://google.de/", true);

            using var runner = TestRunner.Run(redirect);

            using var response = runner.GetResponse();

            Assert.Equal(HttpStatusCode.TemporaryRedirect, response.StatusCode);
            Assert.Equal("https://google.de/", response.Headers["Location"]);
        }
Ejemplo n.º 7
0
        public void TestPermanent()
        {
            var redirect = Redirect.To("https://google.de/");

            using var runner = TestRunner.Run(redirect);

            using var response = runner.GetResponse();

            Assert.Equal(HttpStatusCode.MovedPermanently, response.StatusCode);
            Assert.Equal("https://google.de/", response.Headers["Location"]);
        }
Ejemplo n.º 8
0
        public void TestSimpleRoute()
        {
            var layout = Layout.Create()
                         .Add("redirect", Redirect.To("{index}"))
                         .Index(Content.From("Hello World"));

            using var runner = TestRunner.Run(layout);

            using var response = runner.GetResponse("/redirect");

            Assert.Equal("/", new Uri(response.Headers["Location"]).AbsolutePath);
        }
Ejemplo n.º 9
0
        public void TestTemporaryPost()
        {
            var redirect = Redirect.To("https://google.de/", true);

            using var runner = TestRunner.Run(redirect);

            var request = runner.GetRequest();

            request.Method = "POST";

            using var response = runner.GetResponse(request);

            Assert.Equal(HttpStatusCode.SeeOther, response.StatusCode);
            Assert.Equal("https://google.de/", response.Headers["Location"]);
        }
Ejemplo n.º 10
0
        public void TestPermanentPost()
        {
            var redirect = Redirect.To("https://google.de/", false);

            using var runner = TestRunner.Run(redirect);

            var request = runner.GetRequest();

            request.Method = "POST";

            using var response = runner.GetResponse(request);

            Assert.Equal(HttpStatusCode.PermanentRedirect, response.StatusCode);
            Assert.Equal("https://google.de/", response.Headers["Location"]);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// هدایت کاربر به آدرسی خاص
 /// </summary>
 /// <param name="url">آدرس صفحه</param>
 private void doNavigate(string url)
 {
     if (string.IsNullOrWhiteSpace(url))
     {
         return;
     }
     if (url == "DoLogout") // خروجی از سیستم درخواست شده است
     {
         _appContextService.LogoutCurrentUser();
         Redirect.ToLoginPage();
     }
     else
     {
         Redirect.To(url);
     }
 }
        public IHandlerBuilder Create(Account account, IRequest request)
        {
            EnsureAdmin(request);

            using var context = Database.Create();

            account.Password = AccessControl.Hash(account.Password);
            account.Active   = true;

            account.Created  = DateTime.UtcNow;
            account.Modified = DateTime.UtcNow;

            context.Accounts.Add(account);

            context.SaveChanges();

            return(Redirect.To($"/accounts/", true));
        }
        public IHandlerBuilder?RemoveAnnounces([FromPath] int id, IRequest request)
        {
            using var context = Database.Create();

            var announces = ExtractAnnounces(request, context);

            var letterAnnounces = context.LetterAnnounces
                                  .Where(la => la.Letter.ID == id)
                                  .Where(la => announces.Contains(la.Announce))
                                  .Select(la => la)
                                  .ToList();

            context.LetterAnnounces.RemoveRange(letterAnnounces);

            context.SaveChanges();

            return(Redirect.To($"/letters/details/{id}/", true));
        }
        public IHandlerBuilder?Delete([FromPath] int number)
        {
            using var context = Database.Create();

            var customer = context.Customers
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (customer == null)
            {
                return(null);
            }

            context.Remove(customer);

            context.SaveChanges();

            return(Redirect.To("{controller}/", true));
        }
        public IHandlerBuilder?Publish([FromPath] int id)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            // mark all previous announces as expired ...
            var letterAnnounces = context.LetterAnnounces
                                  .Where(la => la.Letter == letter)
                                  .Select(la => la.Announce)
                                  .ToList();

            var previous = context.Announces
                           .Where(a => a.Status == AnnounceStatus.Published)
                           .Where(a => !letterAnnounces.Contains(a))
                           .ToList();

            foreach (var announce in previous)
            {
                announce.Status = AnnounceStatus.Expired;
            }

            // publish the letter ...
            letter.Status    = LetterStatus.Published;
            letter.Published = DateTime.UtcNow;

            // and it's announces ...
            foreach (var announce in letterAnnounces)
            {
                announce.Status = AnnounceStatus.Published;
            }

            context.SaveChanges();

            return(Redirect.To($"/letters/details/{id}/", true));
        }
        public IHandlerBuilder?Delete([FromPath] int id)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            context.Letters.Remove(letter);

            context.SaveChanges();

            return(Redirect.To("/letters/"));
        }
        public IHandlerBuilder?ReActivate([FromPath] int number)
        {
            using var context = Database.Create();

            var announce = context.Announces
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (announce == null)
            {
                return(null);
            }

            // ToDo: Or Expired?
            announce.Status = AnnounceStatus.Published;

            context.SaveChanges();

            return(Redirect.To($"/announces/details/{number}/", true));
        }
        public IHandlerBuilder?Edit([FromPath] int id, string title)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Include(l => l.Announces)
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            letter.Title = title;

            context.SaveChanges();

            return(Redirect.To($"/letters/details/{id}/", true));
        }
        public IHandlerBuilder?Withdraw([FromPath] int number)
        {
            using var context = Database.Create();

            var announce = context.Announces
                           .Include(a => a.Customer)
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (announce == null)
            {
                return(null);
            }

            announce.Status = AnnounceStatus.Withdrawn;

            context.SaveChanges();

            return(Redirect.To($"/announces/details/{number}/", true));
        }
        public IHandlerBuilder Create(Customer customer)
        {
            using var context = Database.Create();

            if (customer.Number == 0)
            {
                var highest = context.Customers.Max(c => (int?)c.Number);

                customer.Number = (highest != null) ? highest.Value + 1 : START_NUMBER;
            }

            customer.FirstName = OrNull(customer.FirstName);

            customer.Created  = DateTime.UtcNow;
            customer.Modified = DateTime.UtcNow;

            context.Customers.Add(customer);

            context.SaveChanges();

            return(Redirect.To($"{{controller}}/details/{customer.Number}/", true));
        }
        public IHandlerBuilder?Edit([FromPath] int id, Account account, IRequest request)
        {
            var user = AccessControl.GetAccount(request);

            if (!user.Admin && !(user.ID == id))
            {
                throw new ProviderException(ResponseStatus.Forbidden, "Your are not allowed to edit this user.");
            }

            using var context = Database.Create();

            var existing = context.Accounts
                           .Where(c => c.ID == id)
                           .FirstOrDefault();

            if (existing == null)
            {
                return(null);
            }

            existing.Name        = account.Name.Trim();
            existing.DisplayName = account.DisplayName.Trim();

            if (user.Admin)
            {
                existing.Admin = account.Admin;
            }

            if (!string.IsNullOrEmpty(account.Password))
            {
                existing.Password = AccessControl.Hash(account.Password);
            }

            existing.Modified = DateTime.UtcNow;

            context.SaveChanges();

            return(Redirect.To($"{{controller}}/details/{id}/", true));
        }
Ejemplo n.º 22
0
        public IResponse?Handle(IRequest request)
        {
            if (!request.EndPoint.Secure)
            {
                var endpoints = request.Server.EndPoints.Where(e => e.Secure)
                                .ToList();

                if (endpoints.Count > 0)
                {
                    if (Mode == SecureUpgrade.Force)
                    {
                        return(Redirect.To(GetRedirectLocation(request, endpoints))
                               .Build(this)
                               .Handle(request));
                    }
                    else if (Mode == SecureUpgrade.Allow)
                    {
                        if (request.Method.KnownMethod == RequestMethod.GET)
                        {
                            if (request.Headers.TryGetValue("Upgrade-Insecure-Requests", out var flag))
                            {
                                if (flag == "1")
                                {
                                    var response = Redirect.To(GetRedirectLocation(request, endpoints), true)
                                                   .Build(this)
                                                   .Handle(request) !;

                                    response.Headers.Add("Vary", "Upgrade-Insecure-Requests");

                                    return(response);
                                }
                            }
                        }
                    }
                }
            }

            return(Content.Handle(request));
        }
        public IHandlerBuilder?Edit([FromPath] int number, Announce announce)
        {
            using var context = Database.Create();

            var existing = context.Announces
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (existing == null)
            {
                return(null);
            }

            existing.Notes   = OrNull(announce.Notes);
            existing.Title   = OrNull(announce.Title);
            existing.Message = OrNull(announce.Message);

            existing.Modified = DateTime.UtcNow;

            context.SaveChanges();

            return(Redirect.To($"/announces/details/{number}/", true));
        }
        public IHandlerBuilder Create(string title, IRequest request)
        {
            using var context = Database.Create();

            var letter = new Letter()
            {
                Title = title
            };

            letter.Status = LetterStatus.New;

            letter.Created  = DateTime.UtcNow;
            letter.Modified = DateTime.UtcNow;

            context.Letters.Add(letter);

            var announces = ExtractAnnounces(request, context);

            var order = 0;

            foreach (var announce in announces)
            {
                var letterAnnounce = new LetterAnnounce()
                {
                    Letter   = letter,
                    Announce = announce,
                    Order    = order++
                };

                context.LetterAnnounces.Add(letterAnnounce);
            }

            context.SaveChanges();

            return(Redirect.To("/letters/", true));
        }
        public IHandlerBuilder?Create([FromPath] int number, Announce announce)
        {
            using var context = Database.Create();

            var customer = context.Customers
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (customer == null)
            {
                return(null);
            }

            if (announce.Number == 0)
            {
                var highest = context.Announces.Max(c => (int?)c.Number);

                announce.Number = (highest != null) ? highest.Value + 1 : START_NUMBER;
            }

            announce.Customer = customer;
            announce.Status   = AnnounceStatus.New;

            announce.Notes   = OrNull(announce.Notes);
            announce.Message = OrNull(announce.Message);
            announce.Title   = OrNull(announce.Title);

            announce.Created  = DateTime.UtcNow;
            announce.Modified = DateTime.UtcNow;

            context.Announces.Add(announce);

            context.SaveChanges();

            return(Redirect.To($"/announces/details/{announce.Number}/", true));
        }
        public IHandlerBuilder?AddAnnounces([FromPath] int id, IRequest request)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Include(l => l.Announces)
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            var highest = letter.Announces.Max(c => (int?)c.Order);

            int newOrder = (highest != null) ? (int)highest + 1 : 0;

            var announces = ExtractAnnounces(request, context);

            foreach (var announce in announces)
            {
                var letterAnnounce = new LetterAnnounce()
                {
                    Letter   = letter,
                    Announce = announce,
                    Order    = newOrder++
                };

                context.LetterAnnounces.Add(letterAnnounce);
            }

            context.SaveChanges();

            return(Redirect.To($"/letters/details/{id}/", true));
        }
Ejemplo n.º 27
0
 public IHandlerBuilder DoSomethingWithController()
 {
     return(Redirect.To("{controller}/", true));
 }
Ejemplo n.º 28
0
 public IHandlerBuilder DoSomethingWithIndex()
 {
     return(Redirect.To("{index}/", true));
 }
Ejemplo n.º 29
0
 public IHandlerBuilder DoSomethingWithAppenders()
 {
     return(Redirect.To("appenders/1/2/", true));
 }
Ejemplo n.º 30
0
 public IHandlerBuilder DoSomethingWithParent()
 {
     return(Redirect.To("{fallback}/test", true));
 }