Ready to implement login page

This commit is contained in:
Pierre HUBERT 2022-03-30 10:29:10 +02:00
parent 70df96f286
commit 5bc4af399d
7 changed files with 118 additions and 4 deletions

89
Cargo.lock generated
View File

@ -222,6 +222,54 @@ dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "askama"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139"
dependencies = [
"askama_derive",
"askama_escape",
"askama_shared",
]
[[package]]
name = "askama_derive"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71"
dependencies = [
"askama_shared",
"proc-macro2",
"syn",
]
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "askama_shared"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
dependencies = [
"askama_escape",
"humansize",
"mime",
"mime_guess",
"nom",
"num-traits",
"percent-encoding",
"proc-macro2",
"quote",
"serde",
"syn",
"toml",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -250,6 +298,7 @@ name = "basic-oidc"
version = "0.1.0"
dependencies = [
"actix-web",
"askama",
"bcrypt",
"clap",
"env_logger",
@ -633,6 +682,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humansize"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
[[package]]
name = "humantime"
version = "2.1.0"
@ -785,6 +840,12 @@ dependencies = [
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.4.4"
@ -818,6 +879,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "nom"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "ntapi"
version = "0.3.7"
@ -827,6 +898,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.1"
@ -1235,6 +1315,15 @@ dependencies = [
"tracing",
]
[[package]]
name = "toml"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde",
]
[[package]]
name = "tracing"
version = "0.1.32"

View File

@ -16,3 +16,4 @@ serde = { version = "1.0.136", features = ["derive"] }
bcrypt = "0.12.1"
uuid = { version = "0.8.2", features = ["v4"] }
mime_guess = "2.0.4"
askama = "0.11.1"

View File

@ -4,3 +4,6 @@ pub const USERS_LIST_FILE: &str = "users.json";
/// Default built-in credentials
pub const DEFAULT_ADMIN_USERNAME: &str = "admin";
pub const DEFAULT_ADMIN_PASSWORD: &str = "admin";
/// App name
pub const APP_NAME: &str = "Basic OIDC";

View File

@ -0,0 +1,15 @@
use actix_web::Responder;
use askama::Template;
use crate::constants::APP_NAME;
#[derive(Template)]
#[template(path = "login.html")]
struct LoginTemplate<'a> {
app_name: &'a str,
}
pub async fn login_route() -> impl Responder {
LoginTemplate { app_name: APP_NAME }.render().unwrap()
}

View File

@ -1 +1,2 @@
pub mod assets_controller;
pub mod login_controller;

View File

@ -1,8 +1,10 @@
use actix_web::{App, HttpServer, web, get};
use actix_web::{App, get, HttpServer, web};
use actix_web::middleware::Logger;
use clap::Parser;
use basic_oidc::constants::{DEFAULT_ADMIN_PASSWORD, DEFAULT_ADMIN_USERNAME};
use basic_oidc::controllers::assets_controller::assets_route;
use basic_oidc::controllers::login_controller::login_route;
use basic_oidc::data::app_config::AppConfig;
use basic_oidc::data::entity_manager::EntityManager;
use basic_oidc::data::user::{hash_password, User};
@ -50,8 +52,10 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(Logger::default())
.service(health)
.route("/assets/{path:.*}", web::get().to(assets_route))
.route("/login", web::get().to(login_route))
})
.bind(config.listen_address)?
.run()

1
templates/login.html Normal file
View File

@ -0,0 +1 @@
here comes the login page for {{ app_name }}