1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: minor code refactorings

This commit is contained in:
Ferdinand Mütsch
2022-12-29 11:54:14 +01:00
parent 8ca1404f8b
commit bafbc34706
14 changed files with 124 additions and 112 deletions

View File

@ -3,6 +3,7 @@ package models
import (
"crypto/md5"
"fmt"
conf "github.com/muety/wakapi/config"
"regexp"
"strings"
"time"
@ -83,6 +84,10 @@ type CountByUser struct {
Count int64
}
func (u *User) Identity() string {
return u.ID
}
func (u *User) TZ() *time.Location {
if u.Location == "" {
u.Location = "Local"
@ -125,6 +130,15 @@ func (u *User) HasActiveSubscription() bool {
return u.SubscribedUntil != nil && u.SubscribedUntil.T().After(time.Now())
}
func (u *User) MinDataAge() time.Time {
retentionMonths := conf.Get().App.DataRetentionMonths
if retentionMonths <= 0 || u.HasActiveSubscription() {
return time.Time{}
}
// this is not exactly precise, because of summer / winter time, etc.
return time.Now().AddDate(0, -retentionMonths, 0)
}
func (c *CredentialsReset) IsValid() bool {
return ValidatePassword(c.PasswordNew) &&
c.PasswordNew == c.PasswordRepeat