summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller/Account.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2023-01-08 09:40:49 +0100
committerDaniel Friesel <derf@finalrewind.org>2023-01-08 09:40:49 +0100
commit7b2cd23c3998ac2c30b21c0e82ec7a7ea5ece393 (patch)
treea0dc3fbc26dd2fe8aa4d59295ed00172c9f50cf6 /lib/Travelynx/Controller/Account.pm
parentdbd9d9951f8c087c74bb173af8017ce0ac5d8bb9 (diff)
add webfinger "profile-page" support (for public profiles only)
Diffstat (limited to 'lib/Travelynx/Controller/Account.pm')
-rw-r--r--lib/Travelynx/Controller/Account.pm50
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm
index 12b179b..334ec97 100644
--- a/lib/Travelynx/Controller/Account.pm
+++ b/lib/Travelynx/Controller/Account.pm
@@ -6,7 +6,8 @@ package Travelynx::Controller::Account;
use Mojo::Base 'Mojolicious::Controller';
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
-use UUID::Tiny qw(:std);
+use JSON;
+use UUID::Tiny qw(:std);
# Internal Helpers
@@ -967,4 +968,51 @@ sub json_export {
);
}
+sub webfinger {
+ my ($self) = @_;
+
+ my $resource = $self->param('resource');
+
+ if ( not $resource ) {
+ $self->render('not_found');
+ return;
+ }
+
+ my $root_url = $self->url_for('/')->host;
+
+ if ( not $root_url
+ or not $resource =~ m{ ^ (?<name> [^@]+ ) [@] $root_url $ }x )
+ {
+ $self->render('not_found');
+ return;
+ }
+
+ my $name = $+{name};
+ my $user = $self->users->get_privacy_by_name( name => $name );
+
+ if ( not $user or not $user->{public_level} & 0x22 ) {
+ $self->render('not_found');
+ }
+
+ my $profile_url
+ = $self->url_for("/p/${name}")->to_abs->scheme('https')->to_string;
+
+ $self->render(
+ text => JSON->new->encode(
+ {
+ subject => "acct:${resource}",
+ aliases => [ $profile_url, ],
+ links => [
+ {
+ rel => 'http://webfinger.net/rel/profile-page',
+ type => 'text/html',
+ href => $profile_url,
+ },
+ ],
+ }
+ ),
+ format => 'json',
+ );
+}
+
1;