2022-09-28 09:01:17 +02:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Save updates the client session or creates a new one if needed.
|
2022-10-02 11:38:30 +02:00
|
|
|
func (s *Session) Save(m *entity.Session) (*entity.Session, error) {
|
|
|
|
if m == nil {
|
|
|
|
return nil, fmt.Errorf("session is nil")
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save session.
|
2022-10-02 11:38:30 +02:00
|
|
|
return m, m.Save()
|
2022-09-28 09:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create initializes a new client session and returns it.
|
|
|
|
func (s *Session) Create(u *entity.User, c *gin.Context, data *entity.SessionData) (m *entity.Session, err error) {
|
2022-10-02 11:38:30 +02:00
|
|
|
// New session with context, user, and data.
|
|
|
|
m = s.New(c).SetUser(u).SetData(data)
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
// Create session.
|
2022-10-02 11:38:30 +02:00
|
|
|
err = m.Create()
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
return m, err
|
|
|
|
}
|