Create users actor

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

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

@ -1,4 +1,5 @@
pub mod data;
pub mod utils;
pub mod constants;
pub mod controllers;
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()