2022-04-21 07:06:22 +00:00
|
|
|
package cassandradb
|
2022-03-19 12:11:27 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-10 16:19:33 +00:00
|
|
|
"context"
|
2022-04-21 12:41:15 +00:00
|
|
|
"fmt"
|
2022-03-19 12:11:27 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/db/models"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddSession to save session information in database
|
2023-07-31 11:12:11 +00:00
|
|
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
2022-03-19 12:11:27 +00:00
|
|
|
if session.ID == "" {
|
|
|
|
session.ID = uuid.New().String()
|
|
|
|
}
|
|
|
|
session.CreatedAt = time.Now().Unix()
|
|
|
|
session.UpdatedAt = time.Now().Unix()
|
2022-04-21 12:41:15 +00:00
|
|
|
insertSessionQuery := fmt.Sprintf("INSERT INTO %s (id, user_id, user_agent, ip, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Session, session.ID, session.UserID, session.UserAgent, session.IP, session.CreatedAt, session.UpdatedAt)
|
|
|
|
err := p.db.Query(insertSessionQuery).Exec()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-03-19 12:11:27 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-08-01 10:39:17 +00:00
|
|
|
|
|
|
|
// DeleteSession to delete session information from database
|
|
|
|
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
|
|
|
return nil
|
|
|
|
}
|