Micropub-based Blogging Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

session.go 555B

12345678910111213141516171819202122232425262728
  1. package model
  2. import (
  3. "go.rls.moe/webapps/microblog/config"
  4. "go.rls.moe/webapps/microblog/util"
  5. "time"
  6. )
  7. type Session struct {
  8. CreatedAt time.Time
  9. SessionID string `gorm:"index:idx_session_id"`
  10. UserId IDType
  11. User User
  12. }
  13. func (s *Session) BeforeCreate() error {
  14. var err error
  15. s.SessionID, err = util.MakeRandomString(32)
  16. return err
  17. }
  18. func (s *Session) Expired(config *config.Config) bool {
  19. ttl := s.CreatedAt.Add(time.Hour * 24 * time.Duration(config.Session.Lifetime))
  20. if !ttl.After(time.Now()) {
  21. return true
  22. }
  23. return false
  24. }