diff --git a/src/controller/owner.c b/src/controller/owner.c index ad07228..87ed2aa 100644 --- a/src/controller/owner.c +++ b/src/controller/owner.c @@ -2,7 +2,12 @@ #include "http_server/http_request.h" +#include "model/server.h" + +#include "view/layout.h" + #include +#include static void write_public_key( FILE* f ) { @@ -17,9 +22,8 @@ static void write_public_key( FILE* f ) } } -static void handle_owner_actor( struct http_request* req ) +static bool handle_owner_actor( struct http_request* req ) { - const char* server = "apogee.polaris-1.work"; struct account* owner_account = account_from_id(0); http_request_send_headers( req, 200, "application/activity+json", true ); @@ -27,13 +31,33 @@ static void handle_owner_actor( struct http_request* req ) #define RENDER #include "src/view/owner_actor.json.inc" #undef RENDER + + return true; +} + +static bool show_owner_profile_page( struct http_request* req ) +{ + struct account* account = account_from_id(0); + const char* title = "Apogee"; + + http_request_send_headers( req, 200, "text/html", true ); + FILE* f = http_request_get_response_body(req); + #define RENDER + #include "src/view/account_page.html.inc" + #undef RENDER + + return true; } bool route_owner( struct http_request* req ) { - if( http_request_route( req, "/actor" ) ) { - handle_owner_actor(req); - return true; + if( http_request_route_term( req, "/actor" ) ) { + const char* accept = http_request_get_header( req, "Accept" ); + if( 0 == strcmp(accept,"application/ld+json")) { + return handle_owner_actor(req); + } + + return show_owner_profile_page(req); } return false; diff --git a/src/view/account_page.html.template b/src/view/account_page.html.template new file mode 100644 index 0000000..b2443d5 --- /dev/null +++ b/src/view/account_page.html.template @@ -0,0 +1,3 @@ +%( view_begin_layout(f,title); ) +

%s{ account->display_name }

+%( view_end_layout(f); ) diff --git a/src/view/layout.c b/src/view/layout.c new file mode 100644 index 0000000..2aefadd --- /dev/null +++ b/src/view/layout.c @@ -0,0 +1,17 @@ +#include "layout.h" + +void view_begin_layout( FILE* f, const char* title ) +{ + #define RENDER + #define BEGIN + #include "src/view/layout.html.inc" + #undef BEGIN + #undef RENDER +} +void view_end_layout( FILE* f ) +{ + #define RENDER + #include "src/view/layout.html.inc" + #undef RENDER +} + diff --git a/src/view/layout.h b/src/view/layout.h new file mode 100644 index 0000000..423776e --- /dev/null +++ b/src/view/layout.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +void view_begin_layout( FILE* f, const char* title ); +void view_end_layout( FILE* f ); + diff --git a/src/view/layout.html.template b/src/view/layout.html.template new file mode 100644 index 0000000..cf8f28d --- /dev/null +++ b/src/view/layout.html.template @@ -0,0 +1,12 @@ +%( #ifdef BEGIN ) + + + %s{title} + + + +%( #else ) + + + +%( #endif ) diff --git a/src/view/owner_actor.json.template b/src/view/owner_actor.json.template index 386bc7e..77e59a7 100644 --- a/src/view/owner_actor.json.template +++ b/src/view/owner_actor.json.template @@ -4,14 +4,14 @@ "https://w3id.org/security/v1" ], - "id": "https://%s{server}/owner/actor", + "id": "https://%s{g_server_name}/owner/actor", "type": "Person", "preferredUsername": "%s{owner_account->handle}", - "inbox": "https://%s{server}/inbox", + "inbox": "https://%s{g_server_name}/inbox", "publicKey": { - "id": "https://%s{server}/owner/actor#main-key", - "owner": "https://%s{server}/owner/actor", + "id": "https://%s{g_server_name}/owner/actor#main-key", + "owner": "https://%s{g_server_name}/owner/actor", "publicKeyPem": "%( write_public_key(f); )" } }