Ejemplo n.º 1
0
        public async Task Index(HttpRequest request)
        {
            UserSession session = request.Session as UserSession;
            User        user    = await session.GetUser();

            string html = await GetHtml("index");

            if (html == null)
            {
                await request.SetStatusCode(HttpStatusCode.NotFound).Close();

                return;
            }

            request.SetStatusCode(HttpStatusCode.OK);
            request.SetContentType(ContentType.Html);

            HtmlPage page = new HtmlPage(html, user);

            string rendered = await page.Render();

            await request.Write(rendered);

            await request.Close();
        }
Ejemplo n.º 2
0
        public async Task Events(HttpRequest req)
        {
            UserSession session = req.Session as UserSession;
            User        user    = await session.GetUser();

            string html = await GetHtml("events");

            if (html == null)
            {
                await req.SetStatusCode(HttpStatusCode.NotFound).Close();

                return;
            }

            req.SetStatusCode(HttpStatusCode.OK);
            req.SetContentType(ContentType.Html);

            HtmlPage page = new HtmlPage(html, user);

            if (req.HasGET("address"))
            {
                page.Address = req.GET("address", "");
            }

            string rendered = await page.Render();

            await req.Write(rendered);

            await req.Close();
        }
Ejemplo n.º 3
0
        public async Task Admin(HttpRequest req)
        {
            UserSession session = req.Session as UserSession;
            User        user    = await session.GetUser();

            // Redirect non-admins to the index
            if (!session.LoggedIn || user == null || user.Role != UserRole.Admin)
            {
                await req.Redirect("/");

                return;
            }

            string html = await GetHtml("admin");

            if (html == null)
            {
                await req.SetStatusCode(HttpStatusCode.NotFound).Close();

                return;
            }

            req.SetStatusCode(HttpStatusCode.OK);
            req.SetContentType(ContentType.Html);

            HtmlPage page = new HtmlPage(html, user);

            string rendered = await page.Render();

            await req.Write(rendered);

            await req.Close();
        }