A few suggestion fixes.

pull/1500/head
Dessalines 2021-03-19 10:02:58 -04:00
parent 05b485b678
commit 493598c1ba
3 changed files with 11 additions and 3 deletions

View 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 {

View 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(),

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