reprogl
1package models2
3import (4"database/sql"5"strings"6"time"7
8"xelbot.com/reprogl/utils/hashid"9)
10
11type LoggedUser struct {12ID int13Username string14PasswordHash string15Salt string16Role string17}
18
19type User struct {20ID int21Username string22Email string23Role string24DisplayName sql.NullString25Gender int26AvatarVariant int27CreatedAt time.Time28}
29
30func (u *User) Avatar(size int) string {31options := hashid.User32if u.Gender == 1 {33options |= hashid.Male34} else {35options |= hashid.Female36}37
38if u.AvatarVariant > 0 {39options += hashid.Option(u.AvatarVariant << 4)40}41
42return AvatarLink(u.ID, options, size)43}
44
45func (u *User) Nickname() string {46if u.DisplayName.Valid && len(u.DisplayName.String) > 0 {47return u.DisplayName.String48}49
50return u.Username51}
52
53func (u *User) HasDisplayName() bool {54return u.DisplayName.Valid && len(u.DisplayName.String) > 055}
56
57func (u *User) DisplayNameValue() (name string) {58if u.DisplayName.Valid && len(u.DisplayName.String) > 0 {59name = u.DisplayName.String60}61
62return63}
64
65func (u *User) IsMale() bool {66return u.Gender == 167}
68
69func (u *User) NeedToCheckGravatar() bool {70return !strings.Contains(u.Email, "@xelbot.fake")71}
72
73func (u *User) GetEmail() string {74return u.Email75}
76