From: Dessalines Date: Fri, 19 Mar 2021 14:02:58 +0000 (-0400) Subject: A few suggestion fixes. X-Git-Url: http://these/git/%7Bthis.state.user.avatar%7D?a=commitdiff_plain;h=493598c1ba18077086b58770d96aa36a619ca0be;p=lemmy.git A few suggestion fixes. --- diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 4f2251fd..529a13cf 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -118,7 +118,7 @@ pub(crate) fn check_validator_time( validator_time: &chrono::NaiveDateTime, claims: &Claims, ) -> Result<(), LemmyError> { - let user_validation_time = validator_time.timestamp_millis() / 1000; + let user_validation_time = validator_time.timestamp(); if user_validation_time > claims.iat { Err(ApiError::err("not_logged_in").into()) } else { diff --git a/crates/utils/src/claims.rs b/crates/utils/src/claims.rs index fc3c4357..3a444b9a 100644 --- a/crates/utils/src/claims.rs +++ b/crates/utils/src/claims.rs @@ -1,4 +1,5 @@ use crate::settings::structs::Settings; +use chrono::Utc; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; use serde::{Deserialize, Serialize}; @@ -30,7 +31,7 @@ impl Claims { let my_claims = Claims { sub: local_user_id, iss: Settings::get().hostname(), - iat: chrono::Utc::now().timestamp_millis() / 1000, + iat: Utc::now().timestamp(), }; encode( &Header::default(), diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index d64884bf..0990a43d 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -13,6 +13,7 @@ use crate::{ }; use anyhow::{anyhow, Context}; use deser_hjson::from_str; +use log::warn; use merge::Merge; use std::{env, fs, io::Error, net::IpAddr, sync::RwLock}; @@ -24,7 +25,13 @@ static CONFIG_FILE: &str = "config/config.hjson"; lazy_static! { static ref SETTINGS: RwLock = RwLock::new(match Settings::init() { Ok(c) => c, - Err(_) => Settings::default(), + Err(e) => { + warn!( + "Couldn't load settings file, using default settings.\n{}", + e + ); + Settings::default() + } }); }