user_session.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package model // import "miniflux.app/model"
  5. import (
  6. "fmt"
  7. "time"
  8. "miniflux.app/timezone"
  9. )
  10. // UserSession represents a user session in the system.
  11. type UserSession struct {
  12. ID int64
  13. UserID int64
  14. Token string
  15. CreatedAt time.Time
  16. UserAgent string
  17. IP string
  18. }
  19. func (u *UserSession) String() string {
  20. return fmt.Sprintf(`ID="%d", UserID="%d", IP="%s", Token="%s"`, u.ID, u.UserID, u.IP, u.Token)
  21. }
  22. // UseTimezone converts creation date to the given timezone.
  23. func (u *UserSession) UseTimezone(tz string) {
  24. u.CreatedAt = timezone.Convert(tz, u.CreatedAt)
  25. }
  26. // UserSessions represents a list of sessions.
  27. type UserSessions []*UserSession
  28. // UseTimezone converts creation date of all sessions to the given timezone.
  29. func (u UserSessions) UseTimezone(tz string) {
  30. for _, session := range u {
  31. session.UseTimezone(tz)
  32. }
  33. }