Login and status prompts on index

FossilOrigin-Name: c1e980920a8541527e5a7173f8b131b53786dc96b93253c9849f8a88458d270d
This commit is contained in:
me@ow.nekobit.net 2022-02-16 16:07:30 +00:00
parent f75a31fc38
commit 6c85bd83b6
11 changed files with 117 additions and 2 deletions

View file

@ -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

38
dist/ratfe20.css vendored
View file

@ -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;
}

View file

@ -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 = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
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],

View file

@ -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;
}

View file

@ -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

View file

@ -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);
}

View file

@ -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 = {

View file

@ -20,8 +20,25 @@
#include <string.h>
#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;

View file

@ -20,6 +20,7 @@
#define STATUS_H
#include <mastodont.h>
int try_post_status(mastodont_t* api);
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
#endif // STATUS_H

View file

@ -14,6 +14,7 @@
<a href="/"><img src="/ratfe_logo.png" height="42"></a>
<span class="info">%s</span>
<div id="navbar-right" class="alignend">
%s
<!-- Searchbox -->
<form action="/search" method="get">
<input type="textbox" class="group group-left group-inputbox" placeholder="%s" id="searchbox" name="q"><!-- i hate HTML

14
static/post.html Normal file
View file

@ -0,0 +1,14 @@
<form action="." method="post">
<div class="statusbox" >
<textarea name="content" placeholder="Just landed in N.Y." rows="5"></textarea>
<div class="statusfooter">
<div class="statusfooter-left">
Quality content
</div>
<div class="statusfooter-right">
<input type="submit" value="Post">
</div>
</div>
</div>
</form>