2021-03-22 03:07:18 +00:00
|
|
|
package models
|
|
|
|
|
2021-03-31 03:55:19 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var UserType = reflect.TypeOf(User{})
|
2021-03-22 03:07:18 +00:00
|
|
|
|
2021-08-08 20:05:52 +00:00
|
|
|
type UserStatus int
|
|
|
|
|
|
|
|
const (
|
2021-09-14 04:13:58 +00:00
|
|
|
UserStatusInactive UserStatus = 1 // Default for new users
|
|
|
|
UserStatusConfirmed = 2 // Confirmed email address
|
|
|
|
UserStatusApproved = 3 // Approved by an admin and allowed to publicly post
|
|
|
|
UserStatusBanned = 4 // BALEETED
|
2021-08-08 20:05:52 +00:00
|
|
|
)
|
|
|
|
|
2021-03-22 03:07:18 +00:00
|
|
|
type User struct {
|
|
|
|
ID int `db:"id"`
|
|
|
|
|
|
|
|
Username string `db:"username"`
|
|
|
|
Password string `db:"password"`
|
|
|
|
Email string `db:"email"`
|
|
|
|
|
|
|
|
DateJoined time.Time `db:"date_joined"`
|
|
|
|
LastLogin *time.Time `db:"last_login"`
|
|
|
|
|
2021-08-08 20:05:52 +00:00
|
|
|
IsStaff bool `db:"is_staff"`
|
|
|
|
Status UserStatus `db:"status"`
|
2021-04-17 00:01:13 +00:00
|
|
|
|
|
|
|
Name string `db:"name"`
|
|
|
|
Bio string `db:"bio"`
|
|
|
|
Blurb string `db:"blurb"`
|
|
|
|
Signature string `db:"signature"`
|
2021-08-28 13:31:19 +00:00
|
|
|
Avatar *string `db:"avatar"`
|
2021-04-17 00:01:13 +00:00
|
|
|
|
2021-08-08 20:05:52 +00:00
|
|
|
DarkTheme bool `db:"darktheme"`
|
|
|
|
Timezone string `db:"timezone"`
|
2021-04-17 00:01:13 +00:00
|
|
|
|
|
|
|
ShowEmail bool `db:"showemail"`
|
|
|
|
CanEditLibrary bool `db:"edit_library"`
|
|
|
|
|
|
|
|
DiscordSaveShowcase bool `db:"discord_save_showcase"`
|
|
|
|
DiscordDeleteSnippetOnMessageDelete bool `db:"discord_delete_snippet_on_message_delete"`
|
2021-07-30 04:48:30 +00:00
|
|
|
|
|
|
|
MarkedAllReadAt time.Time `db:"marked_all_read_at"`
|
2021-03-22 03:07:18 +00:00
|
|
|
}
|
2021-08-08 20:05:52 +00:00
|
|
|
|
2021-08-17 05:18:04 +00:00
|
|
|
func (u *User) BestName() string {
|
|
|
|
if u.Name != "" {
|
|
|
|
return u.Name
|
|
|
|
}
|
|
|
|
return u.Username
|
|
|
|
}
|
|
|
|
|
2021-08-08 20:05:52 +00:00
|
|
|
func (u *User) IsActive() bool {
|
2021-09-14 04:13:58 +00:00
|
|
|
return u.Status == UserStatusConfirmed
|
2021-08-08 20:05:52 +00:00
|
|
|
}
|