expiration checkj

main
alex 2023-10-21 18:39:10 +02:00
parent 2983531a8c
commit 4c1a12af4c
2 changed files with 26 additions and 20 deletions

View File

@ -100,30 +100,36 @@ func IncomingMessagesHandler() {
replyMessage = "The code you entered is invalid. Please check the code and try again."
} else {
// code found in cache
// check if code is expired
if tempVerify.ExpiredAt.Before(time.Now()) {
logger.AddSystemLog(rslogger.LogTypeWarning, "Received code which was expired from user: %s %s. Message: %s", update.Message.From.FirstName, update.Message.From.LastName, code)
var foundVerifiedUser structs.VerifiedUser
database.DB.Where("chat_id = ?", update.Message.From.ID).First(&foundVerifiedUser)
if foundVerifiedUser.UserId != "" {
// user already verified
replyMessage = "You have already verified your account. You will continue to receive notifications. Type /unsubscribe to stop receiving notifications."
logger.AddSystemLog(rslogger.LogTypeWarning, "User: %s %s has tried to verify his account with code %s, but has already verified his account", update.Message.From.FirstName, update.Message.From.LastName, code)
replyMessage = "The code you entered is expired. Please check the code and try again."
} else {
// user not verified
var foundVerifiedUser structs.VerifiedUser
replyMessage = "You have successfully verified your account. You will now receive notifications. Type /unsubscribe to stop receiving notifications."
database.DB.Where("chat_id = ?", update.Message.From.ID).First(&foundVerifiedUser)
database.DB.Create(&structs.VerifiedUser{
UserId: tempVerify.UserId,
ChatId: update.Message.From.ID,
Filter: utils.NotificationTypeError,
CreatedAt: time.Now(),
})
if foundVerifiedUser.UserId != "" {
// user already verified
logger.AddSystemLog(rslogger.LogTypeInfo, "User: %s %s has subscribed to receive notifications", update.Message.From.FirstName, update.Message.From.LastName)
replyMessage = "You have already verified your account. You will continue to receive notifications. Type /unsubscribe to stop receiving notifications."
logger.AddSystemLog(rslogger.LogTypeWarning, "User: %s %s has tried to verify his account with code %s, but has already verified his account", update.Message.From.FirstName, update.Message.From.LastName, code)
} else {
// user not verified
replyMessage = "You have successfully verified your account. You will now receive notifications. Type /unsubscribe to stop receiving notifications."
database.DB.Create(&structs.VerifiedUser{
UserId: tempVerify.UserId,
ChatId: update.Message.From.ID,
Filter: utils.NotificationTypeError,
CreatedAt: time.Now(),
})
logger.AddSystemLog(rslogger.LogTypeInfo, "User: %s %s has subscribed to receive notifications", update.Message.From.FirstName, update.Message.From.LastName)
}
}
cache.RemoveTempVerifyCode(tempVerify.UserId)

View File

@ -6,7 +6,7 @@ import (
const (
VerifyCodeLength = 6
TempVerifyCodeExpirationTime = 5 * time.Minute
TempVerifyCodeExpirationTime = 10 * time.Minute // also change on admin dashboard web
NotificationIconSuccess = "🟢"
NotificationSymbolInfo = "🔵"