Redirection et page privé de l'utilisateur

principale
kitoy 2022-05-30 01:52:07 +02:00
parent ab6de25744
commit 52f63fb3f0
6 changed files with 877 additions and 560 deletions

61
assets/private.html Normal file
View File

@ -0,0 +1,61 @@
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/style.css">
<title>Portal User</title>
</head>
<body>
<nav class="container-fluid">
<ul>
<li>
<details role="list" >
<summary aria-haspopup="listbox" role="link" class="secondary">Theme</summary>
<ul role="listbox">
<li><a href="#" data-theme-switcher="auto">Auto</a></li>
<li><a href="#" data-theme-switcher="light">Light</a></li>
<li><a href="#" data-theme-switcher="dark">Dark</a></li>
</ul>
</details>
</li>
<li>
<details role="list" >
<summary aria-haspopup="listbox" role="link" class="secondary"> Mon compte </summary>
<ul role="listbox">
<li><a href="#"> Mes services </a> </li>
<li><a href="#"> Documentation </a></li>
<li><a href="#"> Changer mon mot de passe </a></li>
<li><a href="#"> Se déconnecter </a></li>
</ul>
</details>
</li>
</ul>
</nav>
<!-- Header -->
<header class="container">
<hgroup>
<h1> Bienvenue sur kitoy.me </h1>
<h2> Gérez votre compte sur kitoy.me </h2>
</hgroup>
<!-- Nav -->
</header><!-- ./ Header -->
<main class="container">
<h2> Gérer votre compte </h2>
<p>message debug: $msg$</p>
</main>
<!-- Minimal theme switcher -->
<script src="/js/theme-switcher.js"></script>
</body>
</html>

View File

@ -1,5 +0,0 @@
<html>
<body>
<h1> BRAVO </h1>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -38,8 +38,9 @@ domain * {
route /css/style.css asset_serve_style_css
route /js/theme-switcher.js asset_serve_theme_switcher_js
route /signup create_user
route /portal/bienvenue asset_serve_private_test_html auth_example
route /portal/bienvenue private_portal auth_example
route /logout v_session_remove
params post / {
validate login v_login
validate password v_password

BIN
kore.core

Binary file not shown.

View File

@ -34,6 +34,7 @@ int v_password_func(struct http_request *, char *);
int create_user(struct http_request *);
int v_session_validate(struct http_request *, char *);
int v_session_remove(struct http_request *, char *);
int private_portal(struct http_request *);
hashtable_t *hashtable = NULL;
@ -142,9 +143,10 @@ int create_user(struct http_request *req)
}
sqlite3_close(db);
http_response_header(req, "location", "/");
http_response_header(req, "content-type", "text/html");
d = kore_buf_release(b, &len);
http_response(req, 200, d, len);
http_response(req, HTTP_STATUS_FOUND, NULL, 0);
kore_free(d);
return (KORE_RESULT_OK);
@ -266,8 +268,10 @@ int portal_user_load(struct http_request *req)
if (cookie != NULL)
http_response_header(req, "set-cookie", cookie);
d = kore_buf_release(b, &len);
http_response(req, 200, d, len);
kore_free(d);
http_response_header(req, "location", "/portal/bienvenue");
http_response(req, HTTP_STATUS_FOUND, NULL, 0);
kore_free(d);
return (KORE_RESULT_OK);
}
@ -294,10 +298,10 @@ int v_session_remove (struct http_request *req, char *data)
if (ht_get(hashtable, buffer) != NULL)
ht_delete(hashtable, buffer);
http_response_header(req, "location", "/");
http_response_header(req, "content-type", "text/html");
http_response_header(req, "set-cookie", "session_id=");
http_response(req, 200, asset_index_html, asset_len_index_html);
http_response_header(req, "set-cookie", "session_id=""");
http_response(req, HTTP_STATUS_FOUND, NULL, 0);
return (KORE_RESULT_OK);
}
@ -311,3 +315,27 @@ int v_session_validate(struct http_request *req, char *data)
return (KORE_RESULT_ERROR);
}
int private_portal(struct http_request *req)
{
struct kore_buf *b = NULL;
u_int8_t *d = NULL;
size_t len = 0;
if (req->method == HTTP_METHOD_GET)
http_populate_get(req);
b = kore_buf_alloc(asset_len_signup_html);
kore_buf_append(b, asset_private_html, asset_len_private_html);
if (req->method == HTTP_METHOD_GET) {
kore_buf_replace_string(b, "$msg$", "GO", 4);
http_response_header(req, "content-type", "text/html");
d = kore_buf_release(b, &len);
http_response(req, 200, d, len);
kore_free(d);
return (KORE_RESULT_OK);
}
}