Create users actor
This commit is contained in:
parent
70aaa1ff44
commit
bfe4674f88
56
Cargo.lock
generated
56
Cargo.lock
generated
@ -2,6 +2,30 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
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]]
|
[[package]]
|
||||||
name = "actix-codec"
|
name = "actix-codec"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@ -181,6 +205,17 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "adler"
|
name = "adler"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@ -297,6 +332,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
|||||||
name = "basic-oidc"
|
name = "basic-oidc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"actix",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"askama",
|
"askama",
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
@ -479,6 +515,26 @@ dependencies = [
|
|||||||
"cfg-if",
|
"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]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
@ -6,8 +6,9 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.1.6", features = ["derive", "env"] }
|
actix = "0.13.0"
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
|
clap = { version = "3.1.6", features = ["derive", "env"] }
|
||||||
include_dir = "0.7.2"
|
include_dir = "0.7.2"
|
||||||
log = "0.4.16"
|
log = "0.4.16"
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
|
1
src/actors/mod.rs
Normal file
1
src/actors/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod users_actor;
|
18
src/actors/users_actor.rs
Normal file
18
src/actors/users_actor.rs
Normal 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>;
|
||||||
|
}
|
@ -2,3 +2,4 @@ pub mod data;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod controllers;
|
pub mod controllers;
|
||||||
|
pub mod actors;
|
15
src/main.rs
15
src/main.rs
@ -8,6 +8,8 @@ use basic_oidc::controllers::login_controller::login_route;
|
|||||||
use basic_oidc::data::app_config::AppConfig;
|
use basic_oidc::data::app_config::AppConfig;
|
||||||
use basic_oidc::data::entity_manager::EntityManager;
|
use basic_oidc::data::entity_manager::EntityManager;
|
||||||
use basic_oidc::data::user::{hash_password, User};
|
use basic_oidc::data::user::{hash_password, User};
|
||||||
|
use basic_oidc::actors::users_actor::UsersActor;
|
||||||
|
use actix::Actor;
|
||||||
|
|
||||||
#[get("/health")]
|
#[get("/health")]
|
||||||
async fn health() -> &'static str {
|
async fn health() -> &'static str {
|
||||||
@ -48,14 +50,25 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.expect("Failed to create initial user!");
|
.expect("Failed to create initial user!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let users_actor = UsersActor::new(users).start();
|
||||||
|
|
||||||
log::info!("Server will listen on {}", config.listen_address);
|
log::info!("Server will listen on {}", config.listen_address);
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
|
.app_data(web::Data::new(users_actor.clone()))
|
||||||
|
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
|
|
||||||
|
// /health route
|
||||||
.service(health)
|
.service(health)
|
||||||
|
|
||||||
|
// Assets serving
|
||||||
.route("/assets/{path:.*}", web::get().to(assets_route))
|
.route("/assets/{path:.*}", web::get().to(assets_route))
|
||||||
|
|
||||||
|
// Login page
|
||||||
.route("/login", web::get().to(login_route))
|
.route("/login", web::get().to(login_route))
|
||||||
|
.route("/login", web::post().to(login_route))
|
||||||
})
|
})
|
||||||
.bind(config.listen_address)?
|
.bind(config.listen_address)?
|
||||||
.run()
|
.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user