forked from lda/telodendria
Begin work on static login page.
This commit is contained in:
parent
36169181dd
commit
16c31b63d7
5 changed files with 160 additions and 2 deletions
33
src/Html.c
33
src/Html.c
|
@ -44,12 +44,18 @@ HtmlBegin(FILE * stream, char *title)
|
|||
"<meta charset=\"utf-8\">"
|
||||
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
|
||||
"<title>%s | Telodendria</title>"
|
||||
,title
|
||||
);
|
||||
|
||||
fprintf(stream,
|
||||
"<style>"
|
||||
":root {"
|
||||
" color-scheme: dark;"
|
||||
" --accent: #7b8333;"
|
||||
"}"
|
||||
"body {"
|
||||
" margin: auto;"
|
||||
" width: 100%%;"
|
||||
" max-width: 8.5in;"
|
||||
" padding: 0.25in;"
|
||||
" background-color: #0d1117;"
|
||||
|
@ -67,11 +73,36 @@ HtmlBegin(FILE * stream, char *title)
|
|||
" text-align: center;"
|
||||
" font-weight: bold;"
|
||||
"}"
|
||||
);
|
||||
|
||||
fprintf(stream,
|
||||
".form {"
|
||||
" margin: auto;"
|
||||
" width: 100%%;"
|
||||
" max-width: 400px;"
|
||||
" border-radius: 10px;"
|
||||
" border: 1px var(--accent) solid;"
|
||||
" padding: 10px;"
|
||||
"}"
|
||||
"form {"
|
||||
" display: block;"
|
||||
"}"
|
||||
"form > input, label {"
|
||||
" width: 95%%;"
|
||||
" height: 25px;"
|
||||
" display: block;"
|
||||
" margin-bottom: 5px;"
|
||||
" margin-left: auto;"
|
||||
" margin-right: auto;"
|
||||
"}"
|
||||
"</style>"
|
||||
);
|
||||
|
||||
fprintf(stream,
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<pre class=\"logo\">"
|
||||
,title);
|
||||
);
|
||||
|
||||
for (i = 0; i < TELODENDRIA_LOGO_HEIGHT; i++)
|
||||
{
|
||||
|
|
|
@ -23,15 +23,39 @@
|
|||
*/
|
||||
#include <Routes.h>
|
||||
#include <Static.h>
|
||||
#include <Memory.h>
|
||||
|
||||
ROUTE_IMPL(RouteStatic, args)
|
||||
{
|
||||
FILE *stream = HttpStream(args->context);
|
||||
char *pathPart = MATRIX_PATH_POP(args->path);
|
||||
|
||||
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
||||
HttpSendHeaders(args->context);
|
||||
|
||||
StaticItWorks(stream);
|
||||
if (!pathPart)
|
||||
{
|
||||
StaticItWorks(stream);
|
||||
}
|
||||
else if (MATRIX_PATH_EQUALS(pathPart, "client"))
|
||||
{
|
||||
Free(pathPart);
|
||||
pathPart = MATRIX_PATH_POP(args->path);
|
||||
|
||||
if (MATRIX_PATH_EQUALS(pathPart, "login"))
|
||||
{
|
||||
StaticLogin(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticError(stream, HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticError(stream, HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
Free(pathPart);
|
||||
return NULL;
|
||||
}
|
||||
|
|
41
src/Static/StaticError.c
Normal file
41
src/Static/StaticError.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <Static.h>
|
||||
#include <Html.h>
|
||||
#include <Http.h>
|
||||
|
||||
void
|
||||
StaticError(FILE * stream, HttpStatus error)
|
||||
{
|
||||
char title[10];
|
||||
|
||||
sprintf(title, "Error %d", error);
|
||||
|
||||
HtmlBegin(stream, title);
|
||||
|
||||
fprintf(stream, "<h2 style=\"text-align: center\">%s</h2>",
|
||||
HttpStatusToString(error));
|
||||
|
||||
HtmlEnd(stream);
|
||||
}
|
57
src/Static/StaticLogin.c
Normal file
57
src/Static/StaticLogin.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <Static.h>
|
||||
#include <Html.h>
|
||||
|
||||
void
|
||||
StaticLogin(FILE * stream)
|
||||
{
|
||||
HtmlBegin(stream, "Log In");
|
||||
|
||||
fprintf(stream,
|
||||
"<div class=\"form\">"
|
||||
"<form id=\"login-form\">"
|
||||
"<label for=\"user\">Username:</label>"
|
||||
"<input type=\"text\" id=\"user\">"
|
||||
"<label for=\"password\">Password:</label>"
|
||||
"<input type=\"password\" id=\"password\">"
|
||||
"<br>"
|
||||
"<input type=\"submit\" value=\"Log In\">"
|
||||
"</form>"
|
||||
"</div>"
|
||||
);
|
||||
|
||||
fprintf(stream,
|
||||
"<script>"
|
||||
"window.addEventListener('load', () => {"
|
||||
" document.getElementById('login-form').addEventListener('submit', (e) => {"
|
||||
" e.preventDefault();"
|
||||
" /* TODO: Submit form here*/"
|
||||
" });"
|
||||
"});"
|
||||
"</script>"
|
||||
);
|
||||
|
||||
HtmlEnd(stream);
|
||||
}
|
|
@ -26,10 +26,15 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Http.h>
|
||||
|
||||
extern void
|
||||
StaticItWorks(FILE *);
|
||||
|
||||
extern void
|
||||
StaticLogin(FILE *);
|
||||
|
||||
extern void
|
||||
StaticError(FILE *, HttpStatus);
|
||||
|
||||
#endif /* TELODENDRIA_STATIC_H */
|
||||
|
|
Loading…
Reference in a new issue