Procházet zdrojové kódy

Make totp qr codes a proper route

George Baugh před 5 měsíci
rodič
revize
abf1b47830
3 změnil soubory, kde provedl 25 přidání a 2 odebrání
  1. 3 0
      lib/TCMS.pm
  2. 21 1
      lib/Trog/Routes/HTML.pm
  3. 1 1
      www/templates/html/components/totp.tx

+ 3 - 0
lib/TCMS.pm

@@ -103,6 +103,9 @@ sub build_routes {
             $query->{social_meta}  = 1;
             $query->{social_meta}  = 1;
             $query->{primary_post} = {};
             $query->{primary_post} = {};
 
 
+            # Some routes may just need to do serve()
+            $query->{tpsgi} = $tpsgi;
+
             # Redirecting somewhere naughty not allow
             # Redirecting somewhere naughty not allow
             $query->{to} = URI->new( $query->{to} // '' )->path() || $query->{to} if $query->{to};
             $query->{to} = URI->new( $query->{to} // '' )->path() || $query->{to} if $query->{to};
 
 

+ 21 - 1
lib/Trog/Routes/HTML.pm

@@ -8,6 +8,7 @@ use feature qw{signatures state};
 
 
 use Errno qw{ENOENT};
 use Errno qw{ENOENT};
 use File::Touch();
 use File::Touch();
+use File::Basename qw{basename};
 use List::Util();
 use List::Util();
 use List::MoreUtils();
 use List::MoreUtils();
 use Capture::Tiny qw{capture};
 use Capture::Tiny qw{capture};
@@ -211,6 +212,11 @@ our %routes = (
         method   => 'GET',
         method   => 'GET',
         callback => \&Trog::Routes::HTML::icon,
         callback => \&Trog::Routes::HTML::icon,
     },
     },
+    '/totp_qr/(.*)' => {
+        auth     => 1,
+        method   => 'GET',
+        callback => \&Trog::Routes::HTML::totp_qr,
+    },
     '/styles/rss-style.xsl' => {
     '/styles/rss-style.xsl' => {
         method   => 'GET',
         method   => 'GET',
         callback => \&Trog::Routes::HTML::rss_style,
         callback => \&Trog::Routes::HTML::rss_style,
@@ -1610,7 +1616,21 @@ sub metrics ($query) {
 sub icon ($query) {
 sub icon ($query) {
     my $path = $query->{route};
     my $path = $query->{route};
     my $tpath = Trog::Themes::themed("img/icon/$path");
     my $tpath = Trog::Themes::themed("img/icon/$path");
-    return Trog::FileHandler::serve( $tpath, $tpath, $query->{start}, 1, undef  );
+    return $query->{tpsgi}->serve( $tpath, $tpath, $query->{start}, $query->{streaming}, $query->{ranges}, $query->{last_fetched}, $query->{deflate}  );
+}
+
+sub totp_qr ($query) {
+    my $fname = basename($query->{route});
+    # For authenticated content, we have to now do a serve().
+    return $query->{tpsgi}->serve(
+        "totp/$fname",
+        "totp/$fname",
+        $query->{start},
+        $query->{streaming},
+        $query->{ranges},
+        $query->{last_fetched},
+        $query->{deflate},
+    );
 }
 }
 
 
 # TODO make statics, abstract gzipped outputting & header handling
 # TODO make statics, abstract gzipped outputting & header handling

+ 1 - 1
www/templates/html/components/totp.tx

@@ -2,5 +2,5 @@
     Use the following URI, or scan the below QR code into your authenticator Application of choice:<br />
     Use the following URI, or scan the below QR code into your authenticator Application of choice:<br />
     <: $uri :>
     <: $uri :>
     <br />
     <br />
-    <img src="/<: $qr :>" alt="TOTP QR Code" />
+    <img src="/totp_qr/<: $qr :>" alt="TOTP QR Code" />
 </div>
 </div>