]> Untitled Git - lemmy.git/commitdiff
A few suggestion fixes.
authorDessalines <tyhou13@gmx.com>
Fri, 19 Mar 2021 14:02:58 +0000 (10:02 -0400)
committerDessalines <tyhou13@gmx.com>
Fri, 19 Mar 2021 14:02:58 +0000 (10:02 -0400)
crates/api/src/lib.rs
crates/utils/src/claims.rs
crates/utils/src/settings/mod.rs

index 4f2251fdece3b62af1057b6e28a2745f757f522f..529a13cfdc7605b6b45a8fc76a5ef5a4491eca48 100644 (file)
@@ -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 {
index fc3c4357970b7212e8659d1df117b8281a4ccbef..3a444b9a4f3bab6a9d2bb573cd5d89f1111699b2 100644 (file)
@@ -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(),
index d64884bfcdee86268ab89949bb9cac5abe8422a4..0990a43ded26e66d9713a6d6d22a7e0c7f914abf 100644 (file)
@@ -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<Settings> = 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()
+    }
   });
 }