MCPcopy Index your code
hub / github.com/dnote/dnote / CreateSession

Method CreateSession

pkg/server/app/sessions.go:28–46  ·  view source on GitHub ↗

CreateSession returns a new session for the user of the given id

(userID int)

Source from the content-addressed store, hash-verified

26
27// CreateSession returns a new session for the user of the given id
28func (a *App) CreateSession(userID int) (database.Session, error) {
29 key, err := crypt.GetRandomStr(32)
30 if err != nil {
31 return database.Session{}, errors.Wrap(err, "generating key")
32 }
33
34 session := database.Session{
35 UserID: userID,
36 Key: key,
37 LastUsedAt: time.Now(),
38 ExpiresAt: time.Now().Add(24 * 100 * time.Hour),
39 }
40
41 if err := a.DB.Save(&session).Error; err != nil {
42 return database.Session{}, errors.Wrap(err, "saving session")
43 }
44
45 return session, nil
46}
47
48// DeleteUserSessions deletes all existing sessions for the given user. It effectively
49// invalidates all existing sessions.

Callers 1

SignInMethod · 0.95

Calls 2

GetRandomStrFunction · 0.92
NowMethod · 0.65

Tested by

no test coverage detected