lint code.
This commit is contained in:
1 parent
663bf85257
commit
f8d676e5df
9 files changed
+71
-62
No files matched your search
+22
-18
@@ -1,15 +1,15 @@
|
||||
use std::time::Instant;
|
||||
use actix_web::{HttpRequest, Responder, web};
|
||||
use cookie::{CookieJar, Cookie, Key};
|
||||
use actix_web::{web, HttpRequest, Responder};
|
||||
use cookie::time::macros::datetime;
|
||||
use cookie::time::OffsetDateTime;
|
||||
use cookie::{Cookie, CookieJar, Key};
|
||||
use std::time::Instant;
|
||||
|
||||
use minijinja::context;
|
||||
use crate::webui::MiniJinjaRenderer;
|
||||
use serde::Deserialize;
|
||||
use crate::db::external_id::UserId;
|
||||
use crate::services::ReadOnlyServiceFactory;
|
||||
use crate::webui::MiniJinjaRenderer;
|
||||
use crate::SQLiteConnectionFactory;
|
||||
use minijinja::context;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct LoginPayload {
|
||||
@@ -26,18 +26,21 @@ pub async fn login(
|
||||
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 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 mut ret = tmpl_env
|
||||
.render("partials/index/success.html", ctx)?
|
||||
.customize();
|
||||
Ok(ret.insert_header(("Set-Cookie", cookie.to_string())))
|
||||
}
|
||||
|
||||
#[actix_web::post("/logout")]
|
||||
pub async fn logout(conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
|
||||
|
||||
pub async fn logout(
|
||||
conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
) -> 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();
|
||||
@@ -49,19 +52,20 @@ pub async fn logout(conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
}
|
||||
|
||||
#[actix_web::get("/")]
|
||||
pub async fn index(req: HttpRequest,
|
||||
conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
|
||||
|
||||
pub async fn index(
|
||||
req: HttpRequest,
|
||||
conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
) -> 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 userid = authentication_service.get_login(& req);
|
||||
let userid = authentication_service.get_login(&req);
|
||||
let username = userid.clone().unwrap_or("".to_string());
|
||||
let ctx = context!{
|
||||
let ctx = context! {
|
||||
is_logged_in => userid.is_some(),
|
||||
name => username,
|
||||
};
|
||||
tmpl_env.render("index.html", ctx)
|
||||
}
|
||||
}
|
||||
+10
-6
@@ -3,7 +3,13 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use actix_files;
|
||||
use actix_web::{dev::ServiceResponse, error, http::{header::ContentType, StatusCode}, middleware::{ErrorHandlerResponse, ErrorHandlers, Logger}, web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result, Scope};
|
||||
use actix_web::{
|
||||
dev::ServiceResponse,
|
||||
error,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers, Logger},
|
||||
web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result, Scope,
|
||||
};
|
||||
use actix_web_lab::respond::Html;
|
||||
use async_channel;
|
||||
use futures::{pin_mut, select, FutureExt};
|
||||
@@ -13,7 +19,7 @@ use rusqlite::Connection;
|
||||
|
||||
use crate::events::Event;
|
||||
use crate::util::{CustomResult, Error, SQLiteConnectionFactory};
|
||||
use crate::webui::worker::{event_processor_loop};
|
||||
use crate::webui::worker::event_processor_loop;
|
||||
|
||||
mod index_views;
|
||||
mod services;
|
||||
@@ -71,13 +77,11 @@ fn create_auto_reloader(enable_template_autoreload: bool) -> AutoReloader {
|
||||
}
|
||||
|
||||
fn create_static_scope() -> Scope {
|
||||
web::scope("/static").service(
|
||||
actix_files::Files::new("/", "./resources/static/"))
|
||||
web::scope("/static").service(actix_files::Files::new("/", "./resources/static/"))
|
||||
}
|
||||
|
||||
fn create_api_scope() -> Scope {
|
||||
web::scope("/v1")
|
||||
.service(views::push_event)
|
||||
web::scope("/v1").service(views::push_event)
|
||||
}
|
||||
|
||||
fn create_views_scope() -> Scope {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::services::{ReadOnlyServiceFactory, SessionService, UserService};
|
||||
use crate::util::{CustomResult, Error, SQLiteConnectionFactory};
|
||||
use crate::services::{SessionService, ReadOnlyServiceFactory, UserService};
|
||||
|
||||
struct ServicesCache {
|
||||
session_service: SessionService,
|
||||
@@ -13,13 +13,13 @@ struct Services {
|
||||
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};
|
||||
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_authentication_service(&self) -> &SessionService {
|
||||
&self.cache.session_service
|
||||
}
|
||||
|
||||
pub fn get_user_service(&self) -> i32 {
|
||||
@@ -28,4 +28,4 @@ impl Services {
|
||||
// service_factory.get_user_service()
|
||||
88
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,3 @@ pub async fn event_processor_loop(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user