word/edit: subpage alias to writer functionality
[sheet.git] / writer.plp
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);