コード例 #1
0
        //[Authenticate(Forms, "/login/")] // Basic, Digest, Oauth, Api
        public override ViewBase Post(ControllerContext context)
        {
            User user;
            if (!UserService.TryAuthenticateUser(context.User, out user))
            {
                return new StatusCodeView(HttpStatusCode.BadGateway); // TODO: return a better error code that doesn't cause forms authentication to overwrite our response
            }
            else if (!UserService.TryAuthorizeUser(user, UserRole.Admin))
            {
                return new StatusCodeView(HttpStatusCode.Forbidden);
            }

            var config = new Config();
            var updates = config.PopulateWithData(context.Form);

            using (var db = DataService.Connect())
            using (var tx = db.OpenTransaction())
            {
                db.Insert(config);

                ConfigService.InitializeWithConfig(config);
                FileService.PregenerateApp();

                tx.Commit();
            }

            return new JsonView(new AppViewModel());
        }