add comments

This commit is contained in:
catusax
2023-07-23 13:02:14 +08:00
committed by GitHub
parent 5018462559
commit e7652db89c
5 changed files with 13 additions and 5 deletions

View File

@@ -42,11 +42,13 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
return nil
}
// SetMfaSession sets the mfa session with key and value of email
func (c *provider) SetMfaSession(email, key string, expiration int64) error {
c.mfasessionStore.Set(email, key, email, expiration)
return nil
}
// GetMfaSession returns value of given mfa session
func (c *provider) GetMfaSession(email, key string) (string, error) {
val := c.mfasessionStore.Get(email, key)
if val == "" {
@@ -55,6 +57,7 @@ func (c *provider) GetMfaSession(email, key string) (string, error) {
return val, nil
}
// DeleteMfaSession deletes given mfa session from in-memory store.
func (c *provider) DeleteMfaSession(email, key string) error {
c.mfasessionStore.Remove(email, key)
return nil

View File

@@ -12,9 +12,11 @@ type Provider interface {
DeleteAllUserSessions(userId string) error
// DeleteSessionForNamespace deletes the session for a given namespace
DeleteSessionForNamespace(namespace string) error
// SetMfaSession sets the mfa session with key and value of email
SetMfaSession(email, key string, expiration int64) error
// GetMfaSession returns value of given mfa session
GetMfaSession(email, key string) (string, error)
// DeleteMfaSession deletes given mfa session from in-memory store.
DeleteMfaSession(email, key string) error
// SetState sets the login state (key, value form) in the session store

View File

@@ -93,6 +93,7 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
return nil
}
// SetMfaSession sets the mfa session with key and value of email
func (c *provider) SetMfaSession(email, key string, expiration int64) error {
currentTime := time.Now()
expireTime := time.Unix(expiration, 0)
@@ -105,6 +106,7 @@ func (c *provider) SetMfaSession(email, key string, expiration int64) error {
return nil
}
// GetMfaSession returns value of given mfa session
func (c *provider) GetMfaSession(email, key string) (string, error) {
data, err := c.store.Get(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, email, key)).Result()
if err != nil {
@@ -113,6 +115,7 @@ func (c *provider) GetMfaSession(email, key string) (string, error) {
return data, nil
}
// DeleteMfaSession deletes given mfa session from in-memory store.
func (c *provider) DeleteMfaSession(email, key string) error {
if err := c.store.Del(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, email, key)).Err(); err != nil {
log.Debug("Error deleting user session from redis: ", err)