From 6c85bd83b6fb685e5bd9fdbd737ad5d4318f8483 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 16 Feb 2022 16:07:30 +0000 Subject: [PATCH] Login and status prompts on index FossilOrigin-Name: c1e980920a8541527e5a7173f8b131b53786dc96b93253c9849f8a88458d270d --- Makefile | 2 ++ dist/ratfe20.css | 38 ++++++++++++++++++++++++++++++++++++++ src/base_page.c | 7 +++++++ src/cookie.c | 24 ++++++++++++++++++++++++ src/cookie.h | 1 + src/index.c | 10 +++++++++- src/login.c | 4 +++- src/status.c | 17 +++++++++++++++++ src/status.h | 1 + static/index.html | 1 + static/post.html | 14 ++++++++++++++ 11 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 static/post.html diff --git a/Makefile b/Makefile index 61fd53d..e0bb7f0 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,8 @@ $(PAGES_DIR)/account.chtml: $(PAGES_DIR)/account.html ./filec $< data_account_html > $@ $(PAGES_DIR)/login.chtml: $(PAGES_DIR)/login.html ./filec $< data_login_html > $@ +$(PAGES_DIR)/post.chtml: $(PAGES_DIR)/post.html + ./filec $< data_post_html > $@ $(MASTODONT_DIR): git clone $(MASTODONT_URL) || true diff --git a/dist/ratfe20.css b/dist/ratfe20.css index 2c73061..9dc52cb 100644 --- a/dist/ratfe20.css +++ b/dist/ratfe20.css @@ -52,6 +52,15 @@ a #navbar-right { padding-right: 8px; + flex: 1; + flex-direction: row; + align-items: center; +} + +#login-header +{ + margin-right: 15px; + text-decoration: none; } .alignend @@ -381,3 +390,32 @@ ul li:first-child a.sidebarbtn margin: 0; } + +/**************** + * Statusbox * + ****************/ +.statusbox +{ + display: flex; + flex-direction: column; + padding: 5px; +} + +.statusbox textarea +{ + width: 100%; + min-width: 100%; + max-width: 100%; + margin-bottom: 5px; +} + +.statusbox .statusfooter +{ + display: flex; + flex-direction: row; +} + +.statusbox .statusfooter-left +{ + flex: 1; +} diff --git a/src/base_page.c b/src/base_page.c index a647679..efb00b7 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -33,6 +33,7 @@ void render_base_page(struct base_page* page) enum l10n_locale locale = page->locale; char* cookie_read = cookie; struct http_cookie_info info = { 0 }; + char* login_string = "Login / Register"; if (!g_config.changed && cookie) while (1) @@ -44,6 +45,11 @@ void render_base_page(struct base_page* page) { g_config.theme = info.val; } + else if (strcmp(info.key, "logged_in") == 0) + { + if (strcmp(info.val, "t") == 0) + login_string = ""; + } if (!cookie_read) break; } @@ -53,6 +59,7 @@ void render_base_page(struct base_page* page) L10N[locale][L10N_APP_NAME], g_config.theme, L10N[locale][L10N_APP_NAME], + login_string, L10N[locale][L10N_SEARCH_PLACEHOLDER], L10N[locale][L10N_SEARCH_BUTTON], L10N[locale][L10N_HOME], diff --git a/src/cookie.c b/src/cookie.c index 1eff638..2888c5c 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -72,3 +72,27 @@ char* parse_cookies(char* begin, struct http_cookie_info* info) return end ? NULL : begin+1; } + +int cookie_get_val(char* src, char* key, struct http_cookie_info* info) +{ + struct http_cookie_info read_info; + char* src_read; + + while (1) + { + src_read = parse_cookies(src_read, &read_info); + + if (!(read_info.key && read_info.val)) break; + if (strcmp(read_info.key, key) == 0) + { + info->key = read_info.key; + info->val = read_info.val; + info->val_len = read_info.val_len; + return 0; + } + + if (!src_read) break; + } + + return 1; +} diff --git a/src/cookie.h b/src/cookie.h index db651a6..d99d14f 100644 --- a/src/cookie.h +++ b/src/cookie.h @@ -29,5 +29,6 @@ struct http_cookie_info // Stupidly fast simple cookie parser char* parse_cookies(char* begin, struct http_cookie_info* info); +int cookie_get_val(char* src, char* key, struct http_cookie_info* info); #endif // COOKIE_H diff --git a/src/index.c b/src/index.c index 3ea8f89..5c2cf4e 100644 --- a/src/index.c +++ b/src/index.c @@ -22,9 +22,11 @@ #include "../config.h" #include "index.h" #include "status.h" +#include "easprintf.h" // Files #include "../static/index.chtml" +#include "../static/post.chtml" void content_index(mastodont_t* api) { @@ -33,6 +35,7 @@ void content_index(mastodont_t* api) struct mstdnt_status* statuses; struct mstdnt_storage storage; char* status_format; + char* output = NULL; if (mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count)) { status_format = "An error occured loading the timeline"; @@ -46,9 +49,13 @@ void content_index(mastodont_t* api) cleanup = 1; } + try_post_status(api); + + easprintf(&output, "%s %s", data_post_html, status_format); + struct base_page b = { .locale = L10N_EN_US, - .content = status_format, + .content = output, .sidebar_right = NULL }; @@ -58,4 +65,5 @@ void content_index(mastodont_t* api) /* Cleanup */ mastodont_storage_cleanup(&storage); if (cleanup) free(status_format); + if (output) free(output); } diff --git a/src/login.c b/src/login.c index accb2d7..dcb126d 100644 --- a/src/login.c +++ b/src/login.c @@ -75,7 +75,9 @@ void content_login(mastodont_t* api, char** data, size_t data_size) mastodont_obtain_oauth_token(api, &args_token, &oauth_store, &token); // TODO checking, also ^ returns non-zero - printf("Set-Cookie: access_token=%s; HttpOnly; SameSite=Strict;", token.access_token); + printf("Set-Cookie: access_token=%s; HttpOnly; SameSite=Strict;\r\n", token.access_token); + printf("Set-Cookie: logged_in=t; SameSite=Strict"); +// cookie_get_val(cookies, key, http_cookie_info* &info) } struct base_page b = { diff --git a/src/status.c b/src/status.c index 8cd0a3b..ae54370 100644 --- a/src/status.c +++ b/src/status.c @@ -20,8 +20,25 @@ #include #include "status.h" #include "easprintf.h" +#include "query.h" #include "../static/status.chtml" +static void status_post(struct http_query_info* info, void* arg) +{ + mastodont_t* api = arg; + + if (strcmp(info->key, "content") == 0) + { + + } +} + +int try_post_status(mastodont_t* api) +{ + char* post_query = try_handle_post(status_post, api); + return 0; +} + char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size) { char* stat_html, *result = NULL; diff --git a/src/status.h b/src/status.h index 2c595f1..9a12b21 100644 --- a/src/status.h +++ b/src/status.h @@ -20,6 +20,7 @@ #define STATUS_H #include +int try_post_status(mastodont_t* api); char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size); #endif // STATUS_H diff --git a/static/index.html b/static/index.html index 97379d4..f81f732 100644 --- a/static/index.html +++ b/static/index.html @@ -14,6 +14,7 @@ %s