no fucking idea. was on the plane. project runs, tests pass.

This commit is contained in:
didier amyot committed 2023-03-01 14:38:11 -05:00
1 parent 9cc566c9d5
commit fed675f4cb
14 files changed
+133 -40

No files matched your search

+8 -3
View File
@@ -8,6 +8,8 @@ use minijinja::context;
use crate::webui::MiniJinjaRenderer;
use serde::Deserialize;
use crate::db::external_id::UserId;
use crate::services::ReadOnlyServiceFactory;
use crate::SQLiteConnectionFactory;
struct SessionService {
key: Key,
@@ -53,14 +55,17 @@ struct LoginPayload {
pub async fn login(
tmpl_env: MiniJinjaRenderer,
web::Json(form): web::Json<LoginPayload>,
conn_factory: web::Data<SQLiteConnectionFactory>,
) -> actix_web::Result<impl Responder> {
let mut conn = conn_factory.readonly().unwrap(); // todo; to proper 500
let mut service_factory = ReadOnlyServiceFactory::new(&mut conn);
let authentication_service = service_factory.get_authentication_service().unwrap();
let cookie = authentication_service.create_login_cookie(& form.username);
let ctx = context! {
name => form.username,
};
let mut ret = tmpl_env.render("partials/index/success.html", ctx)?.customize();
let s = SessionService::new();
let cookie = s.create_login_cookie(& form.username).to_string();
Ok(ret.insert_header(("Set-Cookie", cookie)))
Ok(ret.insert_header(("Set-Cookie", cookie.to_string())))
}
#[actix_web::post("/logout")]
+2
View File
@@ -24,6 +24,7 @@ use crate::webui::worker::{bob, event_processor_loop};
mod views;
mod worker;
mod index_views;
mod services;
struct MiniJinjaRenderer {
@@ -102,6 +103,7 @@ pub async fn web_ui_main(
.service(index_views::login)
.service(index_views::logout)
.service(views::actions)
.service(views::accounts)
.service(views::overview)
.service(views::overview_submit_button)
.service(views::actions_partials)
+31
View File
@@ -0,0 +1,31 @@
use crate::util::{CustomResult, Error, SQLiteConnectionFactory};
use crate::services::{SessionService, ReadOnlyServiceFactory, UserService};
struct ServicesCache {
session_service: SessionService,
}
struct Services {
conn_fact: SQLiteConnectionFactory,
cache: ServicesCache,
}
impl Services {
pub fn new(conn_fact: SQLiteConnectionFactory) -> Services {
let mut tmp_conn = conn_fact.connection().unwrap();
let session_service = SessionService::from_conn(&mut tmp_conn).unwrap();
let cache = ServicesCache{session_service};
Services { conn_fact, cache }
}
pub fn get_authentication_service(& self) -> &SessionService {
& self.cache.session_service
}
pub fn get_user_service(&self) -> i32 {
// let mut conn = self.conn_fact.readonly().unwrap(); // todo; to proper 500
// let service_factory = ReadOnlyServiceFactory::new(&mut conn);
// service_factory.get_user_service()
88
}
}
+9 -3
View File
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use actix_web::{error, web, HttpRequest, Responder};
use actix_web_lab::__reexports::futures_util::SinkExt;
use clap::builder::TypedValueParser;
use log::info;
use minijinja::context;
@@ -8,7 +9,7 @@ use serde::Deserialize;
use crate::db::users::list_users;
use crate::events::Event;
use crate::services::ServiceFactory;
use crate::services::ReadOnlyServiceFactory;
use crate::util::SQLiteConnectionFactory;
use crate::webui::MiniJinjaRenderer;
@@ -17,13 +18,18 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
tmpl_env.render("actions.html", ())
}
#[actix_web::get("/accounts")]
pub async fn accounts(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
tmpl_env.render("accounts.html", ())
}
#[actix_web::get("/overview")]
pub async fn overview(
tmpl_env: MiniJinjaRenderer,
conn_factory: web::Data<SQLiteConnectionFactory>,
) -> actix_web::Result<impl Responder> {
let conn = conn_factory.readonly().unwrap(); // todo; to proper 500
let service_factory = ServiceFactory::new(&conn);
let mut conn = conn_factory.readonly().unwrap(); // todo; to proper 500
let service_factory = ReadOnlyServiceFactory::new(&mut conn);
let user_service = service_factory.get_user_service();
let users = user_service.list_users().unwrap();
let ctx = context! {