photoprism/internal/session/session_save.go
Michael Mayer 6e74f16a77 Auth: Open album share links in the regular user interface #98 #782
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-02 11:38:30 +02:00

30 lines
674 B
Go

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.
func (s *Session) Save(m *entity.Session) (*entity.Session, error) {
if m == nil {
return nil, fmt.Errorf("session is nil")
}
// Save session.
return m, m.Save()
}
// 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) {
// New session with context, user, and data.
m = s.New(c).SetUser(u).SetData(data)
// Create session.
err = m.Create()
return m, err
}