Content-Length: 298098 | pFad | https://github.com/sebadob/rauthy/commit/1173fa0f5ac517c7797c34e1240cbd37cb54dae6

7A better readable expiry formatting in E-Mails · sebadob/rauthy@1173fa0 · GitHub
Skip to content

Commit

Permalink
better readable expiry formatting in E-Mails
Browse files Browse the repository at this point in the history
Signed-off-by: sebadob <sebastiandobe@mailbox.org>
  • Loading branch information
sebadob committed Nov 20, 2023
1 parent e9d1b56 commit 1173fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions rauthy-models/src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::i18n::email_reset_info::I18nEmailResetInfo;
use crate::i18n::SsrJson;
use actix_web::web;
use askama_actix::Template;
use chrono::DateTime;
use lettre::message::{MultiPart, SinglePart};
use lettre::transport::smtp::authentication;
use lettre::{AsyncSmtpTransport, AsyncTransport};
Expand All @@ -17,7 +18,6 @@ use rauthy_common::constants::{
use rauthy_common::error_response::{ErrorResponse, ErrorResponseType};
use rauthy_notify::Notification;
use std::time::Duration;
use time::OffsetDateTime;
use tokio::sync::mpsc;
use tokio::sync::mpsc::Receiver;
use tracing::{debug, error, info, warn};
Expand Down Expand Up @@ -188,9 +188,7 @@ pub async fn send_email_change_info_new(
"{}/users/{}/email_confirm/{}",
data.issuer, magic_link.user_id, &magic_link.id,
);
let exp = OffsetDateTime::from_unix_timestamp(magic_link.exp)
.unwrap()
.to_string();
let exp = email_ts_prettify(magic_link.exp);

let i18n = I18nEmailChangeInfoNew::build(&user.language);
let text = EMailChangeInfoNewTxt {
Expand Down Expand Up @@ -297,9 +295,7 @@ pub async fn send_pwd_reset(data: &web::Data<AppState>, magic_link: &MagicLink,
"{}/users/{}/reset/{}?type={}",
data.issuer, magic_link.user_id, &magic_link.id, magic_link.usage,
);
let exp = OffsetDateTime::from_unix_timestamp(magic_link.exp)
.unwrap()
.to_string();
let exp = email_ts_prettify(magic_link.exp);

let i18n = I18nEmailReset::build(&user.language);
let text = EmailResetTxt {
Expand Down Expand Up @@ -344,8 +340,7 @@ pub async fn send_pwd_reset(data: &web::Data<AppState>, magic_link: &MagicLink,
}

pub async fn send_pwd_reset_info(data: &web::Data<AppState>, user: &User) {
let exp = OffsetDateTime::from_unix_timestamp(user.password_expires.unwrap())
.expect("Corrupt user password expiry timestamp");
let exp = email_ts_prettify(user.password_expires.unwrap());
let link = format!("{}/auth/v1/account.html", data.public_url);

let i18n = I18nEmailResetInfo::build(&user.language);
Expand Down Expand Up @@ -528,3 +523,11 @@ async fn connect_test_smtp(

Ok(conn)
}

//github.com/ Prettifies unix timestamps for E-Mails in a better readable format for end users
#[inline]
fn email_ts_prettify(ts: i64) -> String {
let dt = DateTime::from_timestamp(ts, 0).unwrap_or_default();
let fmt = dt.format("%d/%m/%Y %H:%M:%S");
format!("{} UTC", fmt)
}
4 changes: 2 additions & 2 deletions rauthy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ SESSION_TIMEOUT=5400
# Lifetime in minutes for reset password magic links (default: 30)
ML_LT_PWD_RESET=30

# Lifetime in minutes for the first password magic link, for setting the initial password. (default: 86400)
ML_LT_PWD_FIRST=86400
# Lifetime in minutes for the first password magic link, for setting the initial password. (default: 4320)
ML_LT_PWD_FIRST=4320

#####################################
############# LOGGING ###############
Expand Down

0 comments on commit 1173fa0

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/1173fa0f5ac517c7797c34e1240cbd37cb54dae6

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy