34 lines
771 B
Go
34 lines
771 B
Go
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
|
|
||
|
|
package model
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
type User struct {
|
||
|
|
ID int64
|
||
|
|
Username string
|
||
|
|
DisplayName string
|
||
|
|
Bio string
|
||
|
|
AvatarPath string
|
||
|
|
PasswordHash string
|
||
|
|
Role string
|
||
|
|
ProfileVisibility string
|
||
|
|
DefaultFavePrivacy string
|
||
|
|
MustResetPassword bool
|
||
|
|
Disabled bool
|
||
|
|
CreatedAt time.Time
|
||
|
|
UpdatedAt time.Time
|
||
|
|
}
|
||
|
|
|
||
|
|
// IsAdmin returns true if the user has the admin role.
|
||
|
|
func (u *User) IsAdmin() bool {
|
||
|
|
return u.Role == "admin"
|
||
|
|
}
|
||
|
|
|
||
|
|
// DisplayNameOrUsername returns the display name if set, otherwise the username.
|
||
|
|
func (u *User) DisplayNameOrUsername() string {
|
||
|
|
if u.DisplayName != "" {
|
||
|
|
return u.DisplayName
|
||
|
|
}
|
||
|
|
return u.Username
|
||
|
|
}
|