Compare commits
2 Commits
db0dc5096b
...
7b81f2c8c4
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b81f2c8c4 | |||
| 4cd448208b |
8
moneymgr_backend/Cargo.lock
generated
8
moneymgr_backend/Cargo.lock
generated
@@ -2044,9 +2044,9 @@ checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy-regex"
|
name = "lazy-regex"
|
||||||
version = "3.4.1"
|
version = "3.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60c7310b93682b36b98fa7ea4de998d3463ccbebd94d935d6b48ba5b6ffa7126"
|
checksum = "191898e17ddee19e60bccb3945aa02339e81edd4a8c50e21fd4d48cdecda7b29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy-regex-proc_macros",
|
"lazy-regex-proc_macros",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -2055,9 +2055,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy-regex-proc_macros"
|
name = "lazy-regex-proc_macros"
|
||||||
version = "3.4.1"
|
version = "3.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4ba01db5ef81e17eb10a5e0f2109d1b3a3e29bac3070fdbd7d156bf7dbd206a1"
|
checksum = "c35dc8b0da83d1a9507e12122c80dea71a9c7c613014347392483a83ea593e04"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ serde_json = "1.0.145"
|
|||||||
light-openid = "1.0.4"
|
light-openid = "1.0.4"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
ipnet = { version = "2.11.0", features = ["serde"] }
|
ipnet = { version = "2.11.0", features = ["serde"] }
|
||||||
lazy-regex = "3.4.1"
|
lazy-regex = "3.4.2"
|
||||||
jwt-simple = { version = "0.12.13", default-features = false, features = ["pure-rust"] }
|
jwt-simple = { version = "0.12.13", default-features = false, features = ["pure-rust"] }
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
rust-embed = { version = "8.7.2" }
|
rust-embed = { version = "8.7.2" }
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ pub struct AppConfig {
|
|||||||
#[clap(short = 'S', long, env, default_value = "")]
|
#[clap(short = 'S', long, env, default_value = "")]
|
||||||
secret: String,
|
secret: String,
|
||||||
|
|
||||||
/// Specify whether the cookie should be transmitted only over secure connections
|
|
||||||
#[clap(long, env)]
|
|
||||||
pub cookie_secure: bool,
|
|
||||||
|
|
||||||
/// Unsecure : for development, bypass authentication, using the account with the given
|
/// Unsecure : for development, bypass authentication, using the account with the given
|
||||||
/// email address by default
|
/// email address by default
|
||||||
#[clap(long, env)]
|
#[clap(long, env)]
|
||||||
@@ -161,23 +157,6 @@ impl AppConfig {
|
|||||||
self.unsecure_auto_login_email().is_some()
|
self.unsecure_auto_login_email().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get auth cookie domain
|
|
||||||
pub fn cookie_domain(&self) -> Option<String> {
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
let domain = self.website_origin.split_once("://")?.1;
|
|
||||||
Some(
|
|
||||||
domain
|
|
||||||
.split_once(':')
|
|
||||||
.map(|s| s.0)
|
|
||||||
.unwrap_or(domain)
|
|
||||||
.to_string(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// In release mode, the web app is hosted on the same origin as the API
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get app secret
|
/// Get app secret
|
||||||
pub fn secret(&self) -> &str {
|
pub fn secret(&self) -> &str {
|
||||||
let mut secret = self.secret.as_str();
|
let mut secret = self.secret.as_str();
|
||||||
|
|||||||
@@ -63,21 +63,20 @@ pub async fn download(
|
|||||||
pub async fn serve_file(req: HttpRequest, file: &File, download_file: bool) -> HttpResult {
|
pub async fn serve_file(req: HttpRequest, file: &File, download_file: bool) -> HttpResult {
|
||||||
if !download_file {
|
if !download_file {
|
||||||
// Check if the browser already knows the etag
|
// Check if the browser already knows the etag
|
||||||
if let Some(c) = req.headers().get(header::IF_NONE_MATCH) {
|
if let Some(c) = req.headers().get(header::IF_NONE_MATCH)
|
||||||
if c.to_str().unwrap_or("") == file.sha512.as_str() {
|
&& c.to_str().unwrap_or("") == file.sha512.as_str()
|
||||||
return Ok(HttpResponse::NotModified().finish());
|
{
|
||||||
}
|
return Ok(HttpResponse::NotModified().finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the browser already knows the file by date
|
// Check if the browser already knows the file by date
|
||||||
if let Some(c) = req.headers().get(header::IF_MODIFIED_SINCE) {
|
if let Some(c) = req.headers().get(header::IF_MODIFIED_SINCE) {
|
||||||
let date_str = c.to_str().unwrap_or("");
|
let date_str = c.to_str().unwrap_or("");
|
||||||
if let Ok(date) = httpdate::parse_http_date(date_str) {
|
if let Ok(date) = httpdate::parse_http_date(date_str)
|
||||||
if date.add(Duration::from_secs(1))
|
&& date.add(Duration::from_secs(1))
|
||||||
>= time_utils::unix_to_system_time(file.time_create as u64)
|
>= time_utils::unix_to_system_time(file.time_create as u64)
|
||||||
{
|
{
|
||||||
return Ok(HttpResponse::NotModified().finish());
|
return Ok(HttpResponse::NotModified().finish());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ pub async fn get_list_of_account(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(limit) = query.limit {
|
if let Some(limit) = query.limit
|
||||||
if list.len() > limit {
|
&& list.len() > limit
|
||||||
list = list[..limit].to_vec();
|
{
|
||||||
}
|
list = list[..limit].to_vec();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(list))
|
Ok(HttpResponse::Ok().json(list))
|
||||||
|
|||||||
@@ -120,16 +120,16 @@ impl FromRequest for AuthExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check IP restriction
|
// Check IP restriction
|
||||||
if let Some(net) = token.ip_net() {
|
if let Some(net) = token.ip_net()
|
||||||
if !net.contains(&remote_ip.0) {
|
&& !net.contains(&remote_ip.0)
|
||||||
log::error!(
|
{
|
||||||
"Trying to use token {:?} from unauthorized IP address: {remote_ip:?}",
|
log::error!(
|
||||||
token.id()
|
"Trying to use token {:?} from unauthorized IP address: {remote_ip:?}",
|
||||||
);
|
token.id()
|
||||||
return Err(actix_web::error::ErrorForbidden(
|
);
|
||||||
"This token cannot be used from this IP address!",
|
return Err(actix_web::error::ErrorForbidden(
|
||||||
));
|
"This token cannot be used from this IP address!",
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for write access
|
// Check for write access
|
||||||
@@ -163,10 +163,10 @@ impl FromRequest for AuthExtractor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update last use (if needed)
|
// Update last use (if needed)
|
||||||
if token.shall_update_time_used() {
|
if token.shall_update_time_used()
|
||||||
if let Err(e) = tokens_service::update_time_used(&token).await {
|
&& let Err(e) = tokens_service::update_time_used(&token).await
|
||||||
log::error!("Failed to refresh last usage of token! {e}");
|
{
|
||||||
}
|
log::error!("Failed to refresh last usage of token! {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle tokens expiration
|
// Handle tokens expiration
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ impl UpdateInboxEntryQuery {
|
|||||||
let constraints = ServerConstraints::default();
|
let constraints = ServerConstraints::default();
|
||||||
|
|
||||||
// Check inbox entry label
|
// Check inbox entry label
|
||||||
if let Some(label) = &self.label {
|
if let Some(label) = &self.label
|
||||||
if !constraints.inbox_entry_label.check_str(label) {
|
&& !constraints.inbox_entry_label.check_str(label)
|
||||||
return Ok(Some("Invalid inbox entry label length!"));
|
{
|
||||||
}
|
return Ok(Some("Invalid inbox entry label length!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the referenced movement
|
// Check the referenced movement
|
||||||
|
|||||||
@@ -55,12 +55,11 @@ impl UpdateMovementQuery {
|
|||||||
if let Ok(movement) =
|
if let Ok(movement) =
|
||||||
get_by_account_label_amount_time(self.account_id, &self.label, self.amount, self.time)
|
get_by_account_label_amount_time(self.account_id, &self.label, self.amount, self.time)
|
||||||
.await
|
.await
|
||||||
|
&& Some(movement.id()) != ref_movement
|
||||||
{
|
{
|
||||||
if Some(movement.id()) != ref_movement {
|
return Ok(Some(
|
||||||
return Ok(Some(
|
"A movement taken at the same time with the same label and the same amount already exists!",
|
||||||
"A movement taken at the same time with the same label and the same amount already exists!",
|
));
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|||||||
Reference in New Issue
Block a user