lint code.
This commit is contained in:
1 parent
663bf85257
commit
f8d676e5df
9 files changed
+52
-43
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use rusqlite::{Connection, params, Row, Transaction, Result};
|
||||
use crate::util::{CustomResult, Error};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use rusqlite::{params, Connection, Result, Row, Transaction};
|
||||
|
||||
pub struct LedgerInternal {}
|
||||
|
||||
@@ -47,8 +47,8 @@ impl LedgerInternal {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_ledger_internal {
|
||||
use crate::migration;
|
||||
use super::*;
|
||||
use crate::migration;
|
||||
|
||||
#[test]
|
||||
fn test_initial_cookie_secret() -> CustomResult<()> {
|
||||
|
||||
+1
-1
@@ -2,10 +2,10 @@ mod _accounts;
|
||||
mod _cheques;
|
||||
mod _external_id;
|
||||
mod _interests;
|
||||
mod _ledger_internal;
|
||||
mod _securities;
|
||||
mod _test_utils;
|
||||
mod _users;
|
||||
mod _ledger_internal;
|
||||
|
||||
pub mod ledger_internal {
|
||||
pub use super::_ledger_internal::*;
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
use actix_web::HttpRequest;
|
||||
use cookie::{CookieJar, Cookie, Key};
|
||||
use cookie::time::OffsetDateTime;
|
||||
use rusqlite::Connection;
|
||||
use crate::db::ledger_internal::LedgerInternal;
|
||||
use crate::{CustomResult, Error};
|
||||
use actix_web::HttpRequest;
|
||||
use cookie::time::OffsetDateTime;
|
||||
use cookie::{Cookie, CookieJar, Key};
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub struct SessionService {
|
||||
key: Key,
|
||||
}
|
||||
|
||||
|
||||
impl SessionService {
|
||||
|
||||
pub fn from_conn(conn: &mut Connection) -> CustomResult<SessionService> {
|
||||
let tx = conn.transaction().map_err(Error::SqlError)?;
|
||||
let secret = LedgerInternal::new().get_cookie_secret(&tx)?;
|
||||
let ret = SessionService{key: Key::derive_from(&secret)};
|
||||
let ret = SessionService {
|
||||
key: Key::derive_from(&secret),
|
||||
};
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub fn create_login_cookie(&self, user_id: &String) -> Cookie {
|
||||
let mut jar = CookieJar::new();
|
||||
jar.private_mut(& self.key).add(Cookie::new("ledger-user-id", user_id.clone()));
|
||||
jar.get("ledger-user-id").unwrap_or(& Cookie::new("ledger-user-id", "")).clone()
|
||||
jar.private_mut(&self.key)
|
||||
.add(Cookie::new("ledger-user-id", user_id.clone()));
|
||||
jar.get("ledger-user-id")
|
||||
.unwrap_or(&Cookie::new("ledger-user-id", ""))
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn _decrypt_cookie(&self, cookie: Cookie<'static>) -> Option<Cookie> {
|
||||
@@ -35,7 +38,8 @@ impl SessionService {
|
||||
// web framework
|
||||
pub fn get_login(&self, req: &HttpRequest) -> Option<String> {
|
||||
req.cookie("ledger-user-id")
|
||||
.and_then(|c|self._decrypt_cookie(c)).map(|c| c.value().to_string())
|
||||
.and_then(|c| self._decrypt_cookie(c))
|
||||
.map(|c| c.value().to_string())
|
||||
}
|
||||
|
||||
pub fn logout(&self) -> Cookie {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use rusqlite::{Connection};
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub struct SecurityDTO{
|
||||
|
||||
}
|
||||
pub struct SecurityDTO {}
|
||||
|
||||
pub struct SecurityService<'a> {
|
||||
conn: &'a Connection,
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
use rusqlite::Connection;
|
||||
use crate::{CustomResult, Error};
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub use crate::services::_users::UserService;
|
||||
pub use crate::services::_authentication::SessionService;
|
||||
pub use crate::services::_users::UserService;
|
||||
|
||||
mod _transactions;
|
||||
mod _users;
|
||||
mod _authentication;
|
||||
mod _securities;
|
||||
mod _transactions;
|
||||
mod _users;
|
||||
|
||||
pub use crate::db::ledger_internal::LedgerInternal;
|
||||
|
||||
|
||||
+17
-13
@@ -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 {
|
||||
@@ -30,14 +30,17 @@ pub async fn login(
|
||||
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,10 +52,11 @@ pub async fn logout(conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
}
|
||||
|
||||
#[actix_web::get("/")]
|
||||
pub async fn index(req: HttpRequest,
|
||||
pub async fn index(
|
||||
req: HttpRequest,
|
||||
conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
|
||||
|
||||
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();
|
||||
|
||||
+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,
|
||||
|
||||
@@ -25,4 +25,3 @@ pub async fn event_processor_loop(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user