예제 #1
0
        public MainModule(IRepository db)
        {
            Get("/", args => {
                this.RequiresAuthentication();
                return View["index.html", BuildIndexViewModel(db, this.GetUser())];
            });

            Get("/{id:guid}", args => {
                this.RequiresAuthentication();
                return View["index.html", BuildIndexViewModel(db, this.GetUser(), args.id)];
            });

            Get("/signup", args => {
                return View["signup.html", new BaseViewModel()];
            });

            Post("/signup", args => {
                var existing = db.GetUserID((string)this.Request.Form.Username);
                if(existing.HasValue)
                    return this.Response.AsRedirect("/login");
                var id = db.CreateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
                var page = new Page { UserID = id, Title = "Your First Page" };
                page.SetDefaults<Page>();
                db.CreatePage(page);
                return this.LoginAndRedirect(id, cookieExpiry: DateTime.Now.AddDays(30));
            });

            Get("/login", args => {
                return View["login.html", new BaseViewModel()];
            });

            Post("/login", args => {
                var id = db.ValidateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
                if(id.HasValue)
                    return this.LoginAndRedirect(id.Value, cookieExpiry: DateTime.Now.AddDays(30));
                return View["login.html", new BaseViewModel()];
            });

            Get("/logout", args => {
                return this.LogoutAndRedirect("~/");
            });

            Get("/metadata", args => {
                return Global.FetchAndParseMetadata(this.Request.Query["url"]);
            });

            Get("/tests", args => {
                return View["tests/tests.html"];
            });
        }
예제 #2
0
        public PagesModule(IRepository db)
            : base("/pages")
        {
            this.RequiresAuthentication();

            Post("/", args => {
                var page = this.Bind<Page>().SetDefaults<Page>();
                page.UserID = this.GetUser().Identifier;
                return db.CreatePage(page);
            });

            Get("/{id:guid}", args => {
                if(this.Request.Query["deep"] != null)
                    return db.ReadPageDeep(args.id);
                return db.ReadPage(args.id);
            });

            Put("/{id:guid}", args => {
                return db.UpdatePage(this.Bind<Page>().SetDefaults<Page>());
            });

            Delete("/{id:guid}", args => {
                return db.DeletePage(args.id);
            });

            Get("/default", args => {
                var defaultPageID = db.ReadDefaultPageID(this.GetUser().Identifier);
                if(this.Request.Query["deep"] != null)
                    return db.ReadPageDeep(defaultPageID);
                return db.ReadPage(defaultPageID);
            });

            Put("/updateorder", args => {
                var ordering = this.Bind<Ordering>();
                ordering.ID = this.GetUser().Identifier;
                db.UpdatePageDisplayOrder(ordering);
                return true;
            });
        }