Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit ee9597e8 authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

wip admin web view

parent 6c5b376a
No related branches found
No related tags found
No related merge requests found
*+* {
box-sizing: border-box;
font-family: Lato, Arial, Helvetica, sans-serif
}
body {
margin: 0;
}
#admin-login-form {
display: grid;
width: 300px;
gap: 20px;
}
#admin-login-form input {
padding: 4px;
}
\ No newline at end of file
document.getElementById('admin-login-form').onsubmit = function (e) {
e.preventDefault();
fetch('/admin/login', { method: 'POST', body: new URLSearchParams(new FormData(e.target)) }).then(res => {
if (res.status >= 200 && res.status < 400) {
console.log(res)
window.location = '/admin/auth/workspace';
}
}).catch(err => console.log(err))
}
\ No newline at end of file
document.getElementById('admin-login-form').onsubmit = function (e) { console.log("Hello JS")
e.preventDefault(); \ No newline at end of file
fetch('/admin/login', { method: 'POST', body: new URLSearchParams(new FormData(e.target)) }).then(res => {
if (res.status >= 200 && res.status < 400) {
console.log(res)
window.location = '/admin/auth/workspace';
}
}).catch(err => console.log(err))
}
\ No newline at end of file
...@@ -67,7 +67,7 @@ where ...@@ -67,7 +67,7 @@ where
if let false = authenticate(&mut req, &token).await { if let false = authenticate(&mut req, &token).await {
return Ok(req.into_response( return Ok(req.into_response(
actix_web::HttpResponse::Unauthorized() actix_web::HttpResponse::Unauthorized()
.body("Error 401 - Unauthorized") // TODO a proper 401 view ? .body("<html><body>Error 401 - Unauthorized - Please go to <a href='/admin/login'>login page</a>.</body></html>") // TODO a proper 401 view ?
.map_into_right_body(), .map_into_right_body(),
)); ));
} }
......
...@@ -8,6 +8,7 @@ use actix_web::{ ...@@ -8,6 +8,7 @@ use actix_web::{
#[get("/workspace")] #[get("/workspace")]
async fn admin_workspace() -> impl Responder { async fn admin_workspace() -> impl Responder {
// TODO return admin static web view with js application
actix_web::HttpResponse::Ok().body("Welcome Admin") actix_web::HttpResponse::Ok().body("Welcome Admin")
} }
...@@ -66,26 +67,33 @@ async fn admin_authenticate( ...@@ -66,26 +67,33 @@ async fn admin_authenticate(
#[get("/login")] #[get("/login")]
pub async fn admin_login() -> impl Responder { pub async fn admin_login() -> impl Responder {
// TODO real HTML doc - create a module with admin views and a js file to load. // TODO create a module with built-in admin static views
HttpResponse::Ok().body( HttpResponse::Ok().body(
" "
<form id='admin-login-form'> <html lang='en' prefix='og: https://ogp.me/ns#'>
<input type='text' name='username'/> <head>
<input type='password' name='password' /> <meta charset='UTF-8'>
<input type='submit' /> <meta http-equiv='X-UA-Compatible' content='IE=edge'>
</form> <meta name='viewport' content='width=device-width, initial-scale=1.0'>
<script> <title>Krutacea - Admin Login</title>
document.getElementById('admin-login-form').onsubmit = function (e) { <link rel='stylesheet' href='/static/default/admin.css'>
e.preventDefault(); </head>
fetch('/admin/login', { method: 'POST', body: new URLSearchParams(new FormData(e.target)) }).then(res => {
if (res.status >= 200 && res.status < 400) {
console.log(res)
window.location = '/admin/auth/workspace';
}
}).catch(err => console.log(err)) <body>
} <form id='admin-login-form'>
</script> <div>
<label for='username'>Admin Id</label>
<input type='text' name='username'/>
</div>
<div>
<label for='password'>Password</label>
<input type='password' name='password' />
</div>
<input type='submit' />
</form>
</body>
<script src='/static/default/admin.js'></script>
</html>
", ",
) )
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment