67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package cache
|
|
|
|
import (
|
|
"jannex/telegram-bot-manager/modules/structs"
|
|
"sync"
|
|
)
|
|
|
|
var tempVerifyCodes = make(map[string]structs.TempVerifyCode)
|
|
var tMu sync.RWMutex
|
|
|
|
func AddTempVerifyCode(tempVerifyCode structs.TempVerifyCode) {
|
|
tMu.Lock()
|
|
defer tMu.Unlock()
|
|
|
|
tempVerifyCodes[tempVerifyCode.UserId] = tempVerifyCode
|
|
}
|
|
|
|
func GetTempVerifyByCode(code string) (userId string, found bool) {
|
|
tMu.RLock()
|
|
defer tMu.RUnlock()
|
|
|
|
for _, v := range tempVerifyCodes {
|
|
if v.Code == code {
|
|
return v.UserId, true
|
|
}
|
|
}
|
|
|
|
return "", false
|
|
}
|
|
|
|
func GetTempVerifyCode(userId string) (string, bool) {
|
|
tMu.RLock()
|
|
defer tMu.RUnlock()
|
|
|
|
if v, ok := tempVerifyCodes[userId]; ok {
|
|
return v.Code, true
|
|
}
|
|
|
|
return "", false
|
|
}
|
|
|
|
func RemoveTempVerifyCode(userId string) {
|
|
tMu.Lock()
|
|
defer tMu.Unlock()
|
|
|
|
delete(tempVerifyCodes, userId)
|
|
}
|
|
|
|
func GetTempVerifyCodes() []structs.TempVerifyCode {
|
|
tMu.RLock()
|
|
defer tMu.RUnlock()
|
|
|
|
var tempVerifyCodesSlice []structs.TempVerifyCode
|
|
|
|
for _, v := range tempVerifyCodes {
|
|
tempVerifyCodesSlice = append(tempVerifyCodesSlice, v)
|
|
}
|
|
|
|
return tempVerifyCodesSlice
|
|
}
|
|
|
|
func RemoveTempVerifyCodes() {
|
|
tMu.Lock()
|
|
defer tMu.Unlock()
|
|
|
|
}
|