FindAllSessionsForUser finds all of the sessions for a user. If forUpdate is set, it will first lock on the user row which can be used to prevent issues with concurrency. If the lock is acquired, it will return a UserNotFoundError and the operation should be retried. If there are no sessions for the
(tx *storage.Connection, userId uuid.UUID, forUpdate bool)
| 323 | // UserNotFoundError and the operation should be retried. If there are no |
| 324 | // sessions for the user, a nil result is returned without an error. |
| 325 | func FindAllSessionsForUser(tx *storage.Connection, userId uuid.UUID, forUpdate bool) ([]*Session, error) { |
| 326 | if forUpdate { |
| 327 | user := &User{} |
| 328 | if err := tx.RawQuery(fmt.Sprintf("SELECT id FROM %q WHERE id = ? LIMIT 1 FOR UPDATE SKIP LOCKED;", user.TableName()), userId).First(user); err != nil { |
| 329 | if errors.Cause(err) == sql.ErrNoRows { |
| 330 | return nil, UserNotFoundError{} |
| 331 | } |
| 332 | |
| 333 | return nil, err |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | var sessions []*Session |
| 338 | if err := tx.Where("user_id = ?", userId).All(&sessions); err != nil { |
| 339 | if errors.Cause(err) == sql.ErrNoRows { |
| 340 | return nil, nil |
| 341 | } |
| 342 | |
| 343 | return nil, err |
| 344 | } |
| 345 | |
| 346 | return sessions, nil |
| 347 | } |
| 348 | |
| 349 | func updateFactorAssociatedSessions(tx *storage.Connection, userID, factorID uuid.UUID, aal string) error { |
| 350 | return tx.RawQuery("UPDATE "+(&pop.Model{Value: Session{}}).TableName()+" set aal = ?, factor_id = ? WHERE user_id = ? AND factor_id = ?", aal, nil, userID, factorID).Exec() |
no test coverage detected