From d735e66d7d9b2d8c9a965ec96753864ff8c306c2 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 25 Sep 2019 18:37:29 +0200 Subject: v2rw: Add Elm & db_edit framework + Convert doc page editing Most of this is copied from v3. I did improve on a few aspects: - db_edit() and db_entry() use VNDB::Schema rather than dynamically querying the DB. This has the minor advantage of a faster startup. - The Elm code generator now writes to multiple files, this avoids the namespace pollution seen in v3's Lib.Gen and makes the dependency graph a bit more lean (i.e. faster incremental builds). - The Elm code generator doesn't update the timestamp of files that haven't been modified. This also speeds up incremental builds, the elm compiler can now skip rebuilding unmodified files. - The Elm API response generator code now uses plain functions rather than code references and all possible responses are now defined in Elm.pm. Turns out most API responses were used from more than a single place, so it makes sense to have them centrally defined. The doc page preview function is also much nicer; I'd like to apply this to all BBCode textareas as well. (Elm.pm itself is ugly as hell though. And we will prolly need some HTML form generation functions in Elm to make that part less verbose) --- util/vndb.pl | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/vndb.pl b/util/vndb.pl index d2b1a964..15db575a 100755 --- a/util/vndb.pl +++ b/util/vndb.pl @@ -13,7 +13,9 @@ BEGIN { ($ROOT = abs_path $0) =~ s{/util/vndb\.pl$}{}; } use lib $ROOT.'/lib'; use SkinFile; use VNDB::Config; +use VNWeb::Auth; use VNWeb::HTML (); +use VNWeb::Validation (); # load the skins @@ -30,6 +32,10 @@ tuwf->{$_} = config->{$_} for keys %{ config() }; TUWF::set %{ config->{tuwf} }; +# Signal to VNWeb::Elm whether it should generate the Elm files. +# Should be done before loading any more modules. +tuwf->{elmgen} = $ARGV[0] && $ARGV[0] eq 'elmgen'; + TUWF::hook before => sub { # If we're running standalone, serve www/ and static/ too. @@ -62,5 +68,33 @@ TUWF::set error_404_handler => sub { }; -TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler', 'VNWeb'); -TUWF::run(); +sub TUWF::Object::resDenied { + tuwf->resStatus(403); + VNWeb::HTML::framework_ title => 'Access Denied', noindex => 1, sub { + div_ class => 'mainbox', sub { + h1_ 'Access Denied'; + div_ class => 'warning', sub { + if(!auth) { + h2_ 'You need to be logged in to perform this action.'; + p_ sub { + txt_ 'Please '; + a_ href => '/u/login', 'login'; + txt_ ' or '; + a_ href => '/u/register', 'create an account'; + txt_ " if you don't have one yet."; + } + } else { + h2_ 'You are not allowed to perform this action.'; + p_ 'You do not have the proper rights to perform the action you wanted to perform.'; + } + } + } + } +} + + +TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler'); +TUWF::set import_modules => 0; +TUWF::load_recursive('VNWeb'); + +TUWF::run if !tuwf->{elmgen}; -- cgit v1.2.3