word/edit: subpage alias to writer functionality
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 2 Jul 2021 16:54:30 +0000 (18:54 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 5 Jul 2021 01:54:37 +0000 (03:54 +0200)
common.inc.plp
word.plp
writer.plp

index dd41751a5789d861a4559312e98d745a78878c36..f7ca70023bf9a7ff386cb5a9fabbebc37117e465 100644 (file)
@@ -47,10 +47,10 @@ BEGIN {
        our $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
 }
 
-our $Request = decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r);
+our $Request //= decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r);
 
 our $style;
-our $showkeys = !exists $get{keys} ? undef :
+our $showkeys //= !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
 
 $header{content_type} = 'text/html; charset=utf-8';
index 493bde927b655aadff77009072ad8df21f8a414e..a7acea5ae10d9874e3324b8ffc4117ed27077531 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,5 +1,10 @@
 <(common.inc.plp)><:
 
+if ($Request and $Request =~ s{^edit/?}{}) {
+       Include 'writer.plp';
+       exit;
+}
+
 my $lang = $get{lang} || 'en';
 my $wordlist = "data/wordlist.$lang.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
index 256a074369a3c00c5754e8cdfa4a4de735dcc684..84dc4a8a2b66795ca574173d6e9d96fd6dd6b7d3 100644 (file)
@@ -18,6 +18,7 @@ my $db = eval {
 } or Abort('Database error', 501, $@);
 
 my $user = eval {
+       my $rootpath = ($ENV{REQUEST_URI} // '/writer') =~ s{(?<!^)/.+}{}r;
        if (defined $post{username}) {
                $cookie{login} = EncodeURI(join ':', @post{qw( username pass )});
        }
@@ -26,7 +27,7 @@ my $user = eval {
                if (AddCookie(CGI::Cookie->new(
                        -name    => 'login',
                        -value   => '',
-                       -path    => '/writer',
+                       -path    => $rootpath,
                        -expires => 'now',
                )->as_string)) {
                        delete $cookie{login};
@@ -46,7 +47,7 @@ my $user = eval {
                my $httpcookie = CGI::Cookie->new(
                        -name    => 'login',
                        -value   => join(':', @{$found}{qw( username pass )}),
-                       -path    => '/writer',
+                       -path    => $rootpath,
                ) or die "prepared object is empty\n";
                AddCookie($httpcookie->as_string);
        } or Abort(["Unable to create login cookie", $@], 403);