Create users actor
This commit is contained in:
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>;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
pub mod data;
|
||||
pub mod utils;
|
||||
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::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()
|
||||
|
Reference in New Issue
Block a user