forked from mirrors/treebird
Fix login fields
FossilOrigin-Name: 53f1214d19b4f3cb060d88d344c7cbb8bd6823d63dbeca49da49d46600ef4f49
This commit is contained in:
parent
7da8be98ed
commit
c7daed2bd7
8 changed files with 13 additions and 45 deletions
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ CC ?= cc
|
|||
GIT ?= git
|
||||
MASTODONT_DIR = mastodont-c/
|
||||
MASTODONT = $(MASTODONT_DIR)libmastodont.a
|
||||
CFLAGS += -Wall -I $(MASTODONT_DIR)include/
|
||||
CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers
|
||||
LDFLAGS = -L$(MASTODONT_DIR) -lcurl -lmastodont -lcjson
|
||||
SRC = $(wildcard src/*.c)
|
||||
OBJ = $(patsubst %.c,%.o,$(SRC))
|
||||
|
|
|
@ -35,7 +35,6 @@ void render_base_page(struct base_page* page)
|
|||
|
||||
if (!g_config.changed && cookie)
|
||||
{
|
||||
|
||||
if (cookies.theme)
|
||||
g_config.theme = cookies.theme;
|
||||
if (cookies.logged_in && strcmp(cookies.logged_in, "t") == 0)
|
||||
|
@ -65,7 +64,7 @@ void render_base_page(struct base_page* page)
|
|||
return;
|
||||
}
|
||||
|
||||
printf("Content-Length: %d\r\n\r\n%s", len + 1, data);
|
||||
printf("Content-Length: %d\r\n\r\n", len + 1);
|
||||
puts(data);
|
||||
|
||||
free(data);
|
||||
|
|
31
src/login.c
31
src/login.c
|
@ -27,32 +27,13 @@
|
|||
// Files
|
||||
#include "../static/login.chtml"
|
||||
|
||||
struct login_info
|
||||
{
|
||||
char* username;
|
||||
char* password;
|
||||
};
|
||||
|
||||
static void authenticate(struct http_query_info* info, void* _args)
|
||||
{
|
||||
struct login_info* login = _args;
|
||||
|
||||
if (strcmp(info->key, "username") == 0)
|
||||
login->username = info->val;
|
||||
else if (strcmp(info->key, "password") == 0)
|
||||
login->password = info->val;
|
||||
}
|
||||
|
||||
void content_login(mastodont_t* api, char** data, size_t data_size)
|
||||
{
|
||||
char* post_query;
|
||||
struct mstdnt_storage storage, oauth_store;
|
||||
struct mstdnt_app app;
|
||||
struct mstdnt_oauth_token token;
|
||||
struct login_info info = { 0 };
|
||||
|
||||
post_query = try_handle_post(authenticate, &info);
|
||||
if (post_query)
|
||||
if (post.username && post.password)
|
||||
{
|
||||
// Getting the client id/secret
|
||||
struct mstdnt_app_register_args args_app = {
|
||||
|
@ -68,16 +49,15 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
.grant_type = "password",
|
||||
.client_id = app.client_id,
|
||||
.client_secret = app.client_secret,
|
||||
.username = info.username,
|
||||
.password = info.password
|
||||
.username = post.username,
|
||||
.password = post.password
|
||||
};
|
||||
|
||||
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;\r\n", token.access_token);
|
||||
printf("Set-Cookie: logged_in=t; SameSite=Strict");
|
||||
// cookie_get_val(cookies, key, http_cookie_info* &info)
|
||||
printf("Set-Cookie: logged_in=t; SameSite=Strict\r\n");
|
||||
}
|
||||
|
||||
struct base_page b = {
|
||||
|
@ -88,7 +68,4 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
|
||||
// Cleanup
|
||||
if (post_query) free(post_query);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "login.h"
|
||||
#include "local_config.h"
|
||||
#include "cookie.h"
|
||||
#include "query.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
|
|
@ -30,21 +30,8 @@
|
|||
#include "../static/index.chtml"
|
||||
#include "../static/config.chtml"
|
||||
|
||||
static void config_post(struct http_query_info* info, void* args)
|
||||
{
|
||||
(void)args;
|
||||
|
||||
if (strcmp(info->key, "theme") == 0)
|
||||
{
|
||||
g_config.theme = info->val;
|
||||
|
||||
g_config.changed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void content_config(mastodont_t* api, char** data, size_t size)
|
||||
{
|
||||
char* post_query;
|
||||
(void)api; // No need to use this
|
||||
|
||||
if (post.theme)
|
||||
|
|
|
@ -36,7 +36,9 @@ char* read_post_data()
|
|||
{ "content", &(post.content) },
|
||||
{ "itype", &(post.itype) },
|
||||
{ "id", &(post.id) },
|
||||
{ "theme", &(post.theme) }
|
||||
{ "theme", &(post.theme) },
|
||||
{ "username", &(post.username) },
|
||||
{ "password", &(post.password) },
|
||||
};
|
||||
// END Query references
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ struct query_values
|
|||
char* content;
|
||||
char* itype;
|
||||
char* id;
|
||||
char* username;
|
||||
char* password;
|
||||
};
|
||||
|
||||
extern struct query_values post;
|
||||
|
|
|
@ -50,7 +50,7 @@ int try_post_status(mastodont_t* api)
|
|||
mastodont_create_status(api, &args, &storage);
|
||||
|
||||
// TODO cleanup when errors are properly implemented
|
||||
// mastodont_storage_cleanup(&storage);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue