From 493598c1ba18077086b58770d96aa36a619ca0be Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Fri, 19 Mar 2021 10:02:58 -0400
Subject: [PATCH] A few suggestion fixes.

---
 crates/api/src/lib.rs            | 2 +-
 crates/utils/src/claims.rs       | 3 ++-
 crates/utils/src/settings/mod.rs | 9 ++++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

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<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()
+    }
   });
 }
 
-- 
2.44.1