CreateSession returns a new session for the user of the given id
(userID int)
| 26 | |
| 27 | // CreateSession returns a new session for the user of the given id |
| 28 | func (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. |
no test coverage detected