mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
New function login() (untested).
This commit is contained in:
parent
b2c8264003
commit
b3b15cec29
1 changed files with 24 additions and 0 deletions
24
html.c
24
html.c
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "xs.h"
|
||||
#include "xs_io.h"
|
||||
#include "xs_encdec.h"
|
||||
#include "xs_json.h"
|
||||
#include "xs_regex.h"
|
||||
|
||||
|
@ -118,6 +119,29 @@ d_char *not_really_markdown(char *content, d_char **f_content)
|
|||
}
|
||||
|
||||
|
||||
int login(snac *snac, char *headers)
|
||||
/* tries a login */
|
||||
{
|
||||
int logged_in = 0;
|
||||
char *auth = xs_dict_get(headers, "authorization");
|
||||
|
||||
if (auth && xs_startswith(auth, "Basic ")) {
|
||||
int sz;
|
||||
xs *s1 = xs_crop(xs_dup(auth), 6, 0);
|
||||
xs *s2 = xs_base64_dec(s1, &sz);
|
||||
xs *l1 = xs_split_n(s2, ":", 1);
|
||||
|
||||
if (xs_list_len(l1) == 2) {
|
||||
logged_in = check_password(
|
||||
xs_list_get(l1, 0), xs_list_get(l1, 1),
|
||||
xs_dict_get(snac->config, "passwd"));
|
||||
}
|
||||
}
|
||||
|
||||
return logged_in;
|
||||
}
|
||||
|
||||
|
||||
int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
|
||||
{
|
||||
int status = 0;
|
||||
|
|
Loading…
Reference in a new issue