Scaffold login route, front-end CSS

main
Charlotte Som 2021-07-29 23:28:33 +01:00
parent 5e16bb6fd1
commit ce257c3cc1
6 changed files with 163 additions and 14 deletions

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
[*.rs]
indent_size = 4

36
panel/css/chat.css Normal file
View File

@ -0,0 +1,36 @@
.chat-box {
display: flex;
flex-direction: column;
padding: 1em;
height: 12em;
}
.chat-entries {
display: flex;
flex: 1;
margin: 0;
padding: 0.5em;
flex-direction: column-reverse;
overflow-y: scroll;
}
.chat-input {
padding: 0.5em;
}
.chat-message {
display: flex;
}
.message-author {
margin-inline-end: 0.5ch;
}
.message-content {
display: inline-block;
flex: 1;
overflow-wrap: anywhere;
}

43
panel/css/styles.css Normal file
View File

@ -0,0 +1,43 @@
html {
font-family: sans-serif;
margin: 0;
}
body {
min-height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
}
nav,
main,
footer {
max-width: 80ch;
margin: 0 auto;
width: 100%;
padding: 1em;
}
main {
flex: 1;
}
nav ul {
display: block;
margin: 0;
padding: 0;
}
nav li,
nav li a {
display: inline-block;
}
nav li a {
padding: 0.5em;
}
a {
color: rgb(252, 38, 145);
}

40
panel/index.html Normal file
View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat</title>
<link rel="stylesheet" href="/css/styles.css">
<link rel="stylesheet" href="/css/chat.css">
</head>
<body>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/login/">Login</a></li>
<li><a href="/register/">Register</a></li>
</ul>
</nav>
<main>
<h1>Chat</h1>
<section class="chat-box">
<ul class="chat-entries">
<li class="chat-message"><strong class="message-author">user:</strong> <span class="message-content">bbb</span></li>
<li class="chat-message"><strong class="message-author">user:</strong> <span class="message-content">aaa</span></li>
<li class="chat-message"><strong class="message-author">user:</strong> <span class="message-content">123456</span></li>
<li class="chat-message"><strong class="message-author">user:</strong> <span class="message-content">looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</span></li>
<li class="chat-message"><strong class="message-author">user:</strong> <span class="message-content">123456</span></li>
</ul>
<input type="text" class="chat-input">
</section>
</main>
<footer>
by <a href="https://lavender.software">Lavender Software</a>
</footer>
</body>
</html>

8
src/auth.rs Normal file
View File

@ -0,0 +1,8 @@
use std::collections::HashMap;
use warp::{Rejection, Reply};
pub async fn login(form: HashMap<String, String>) -> Result<impl Reply, Rejection> {
// TODO: Accept 'username' and 'password', I guess.
Ok("Hello!".to_string())
}

View File

@ -1,14 +1,24 @@
use warp::{Filter, Rejection, Reply};
use std::net::SocketAddr;
use warp::Filter;
mod auth;
mod db;
mod users;
async fn hello() -> Result<impl Reply, Rejection> {
Ok("Hello!".to_string())
}
#[tokio::main]
async fn main() {
let hello = warp::any().and_then(hello);
warp::serve(hello).run(([127, 0, 0, 1], 8000)).await;
let login_route = warp::path("login")
.and(warp::path::end())
.and(warp::post())
.and(warp::body::form())
.and_then(auth::login);
let panel_route = warp::fs::dir("panel");
let routes = login_route.or(panel_route);
let addr: SocketAddr = ([127, 0, 0, 1], 8000).into();
println!("Listening on: http://{}/ ...", &addr);
warp::serve(routes).run(addr).await;
}