dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 3972794caa32f9adb977da805f595e2de085cf2d
parent 2884d9537f9eaa234be0d541f3e9df72eef94080
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu,  8 Feb 2024 20:44:36 -0800

Have DKF bot notify a user logging in with his PGP key as 2FA if the key expires in less than a month

Diffstat:
Mpkg/database/utils/utils.go | 8++++++--
Mpkg/web/handlers/login.go | 7+++++++
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/pkg/database/utils/utils.go b/pkg/database/utils/utils.go @@ -19,10 +19,14 @@ func GetZeroUser(db *database.DkfDB) database.User { return zeroUser } -func RootAdminNotify(db *database.DkfDB, msg string) { +func ZeroSendMsg(db *database.DkfDB, recipientID database.UserID, msg string) { zeroUser := GetZeroUser(db) + _, _ = db.CreateMsg(msg, msg, "", config.GeneralRoomID, zeroUser.ID, &recipientID) +} + +func RootAdminNotify(db *database.DkfDB, msg string) { rootAdminID := database.UserID(config.RootAdminID) - _, _ = db.CreateMsg(msg, msg, "", config.GeneralRoomID, zeroUser.ID, &rootAdminID) + ZeroSendMsg(db, rootAdminID, msg) } func SendNewChessGameMessages(db *database.DkfDB, key, roomKey string, roomID database.RoomID, zeroUser, player1, player2 database.User) { diff --git a/pkg/web/handlers/login.go b/pkg/web/handlers/login.go @@ -6,6 +6,7 @@ import ( "dkforest/pkg/captcha" "dkforest/pkg/config" "dkforest/pkg/database" + dutils "dkforest/pkg/database/utils" "dkforest/pkg/managers" "dkforest/pkg/utils" hutils "dkforest/pkg/web/handlers/utils" @@ -178,6 +179,12 @@ func SessionsGpgTwoFactorHandler(c echo.Context, step1 bool, token string) error data.Error = err.Error() return c.Render(http.StatusOK, "sessions-gpg-two-factor", data) } + if expiredTime, _ := utils.GetKeyExpiredTime(user.GPGPublicKey); expiredTime != nil { + if expiredTime.AddDate(0, -1, 0).Before(time.Now()) { + chatMsg := fmt.Sprintf("Your PGP key expires in less than a month (%s)", expiredTime.Format("Jan 02, 2006 15:04:05")) + dutils.ZeroSendMsg(db, user.ID, chatMsg) + } + } data.EncryptedMessage = msg return c.Render(http.StatusOK, "sessions-gpg-two-factor", data) }