Create users actor

This commit is contained in:
Pierre HUBERT 2022-03-30 11:40:03 +02:00
parent 70aaa1ff44
commit bfe4674f88
6 changed files with 93 additions and 3 deletions

56
Cargo.lock generated
View File

@ -2,6 +2,30 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "actix"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5"
dependencies = [
"actix-rt",
"actix_derive",
"bitflags",
"bytes",
"crossbeam-channel",
"futures-core",
"futures-sink",
"futures-task",
"futures-util",
"log",
"once_cell",
"parking_lot",
"pin-project-lite",
"smallvec",
"tokio",
"tokio-util 0.7.1",
]
[[package]]
name = "actix-codec"
version = "0.5.0"
@ -181,6 +205,17 @@ dependencies = [
"syn",
]
[[package]]
name = "actix_derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "adler"
version = "1.0.2"
@ -297,6 +332,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
name = "basic-oidc"
version = "0.1.0"
dependencies = [
"actix",
"actix-web",
"askama",
"bcrypt",
@ -479,6 +515,26 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]]
name = "crypto-common"
version = "0.1.3"

View File

@ -6,8 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "3.1.6", features = ["derive", "env"] }
actix = "0.13.0"
actix-web = "4"
clap = { version = "3.1.6", features = ["derive", "env"] }
include_dir = "0.7.2"
log = "0.4.16"
serde_json = "1.0.79"

1
src/actors/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod users_actor;

18
src/actors/users_actor.rs Normal file
View File

@ -0,0 +1,18 @@
use actix::{Actor, Context};
use crate::data::entity_manager::EntityManager;
use crate::data::user::User;
pub struct UsersActor {
manager: EntityManager<User>,
}
impl UsersActor {
pub fn new(manager: EntityManager<User>) -> Self {
Self { manager }
}
}
impl Actor for UsersActor {
type Context = Context<Self>;
}

View File

@ -2,3 +2,4 @@ pub mod data;
pub mod utils;
pub mod constants;
pub mod controllers;
pub mod actors;

View File

@ -8,6 +8,8 @@ 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};
use basic_oidc::actors::users_actor::UsersActor;
use actix::Actor;
#[get("/health")]
async fn health() -> &'static str {
@ -48,14 +50,25 @@ async fn main() -> std::io::Result<()> {
.expect("Failed to create initial user!");
}
let users_actor = UsersActor::new(users).start();
log::info!("Server will listen on {}", config.listen_address);
HttpServer::new(|| {
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(users_actor.clone()))
.wrap(Logger::default())
// /health route
.service(health)
// Assets serving
.route("/assets/{path:.*}", web::get().to(assets_route))
// Login page
.route("/login", web::get().to(login_route))
.route("/login", web::post().to(login_route))
})
.bind(config.listen_address)?
.run()