editing and maintenance and user suggestions
* every user has a right of a username and a display name and has the right to change it * System information page now shows information about database user count, char count, and database schema version * more maintenance lists * show the right values in columns and fields * move similar from inside of frontend component functions to utility js when used multiple times * display help on mouse over * add more than one believe to character * make char name editable with better char info in headline * GiT Gifttoleranz value not calculated correctly * Bump backend to 0.2.3, frontend to 0.2.2
This commit is contained in:
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"bamort/database"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -18,6 +19,7 @@ const (
|
||||
type User struct {
|
||||
UserID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"unique" json:"username"`
|
||||
DisplayName string `gorm:"not null;default:''" json:"display_name"`
|
||||
PasswordHash string `json:"password"`
|
||||
Email string `gorm:"unique" json:"email"`
|
||||
Role string `gorm:"default:standard" json:"role"`
|
||||
@@ -33,6 +35,10 @@ func (object *User) Create() error {
|
||||
return fmt.Errorf("database connection is nil")
|
||||
}
|
||||
|
||||
if strings.TrimSpace(object.DisplayName) == "" {
|
||||
object.DisplayName = object.Username
|
||||
}
|
||||
|
||||
err := database.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// Save the User record
|
||||
if err := tx.Create(&object).Error; err != nil {
|
||||
@@ -75,6 +81,10 @@ func (object *User) Save() error {
|
||||
return fmt.Errorf("database connection is nil")
|
||||
}
|
||||
|
||||
if strings.TrimSpace(object.DisplayName) == "" {
|
||||
object.DisplayName = object.Username
|
||||
}
|
||||
|
||||
err := database.DB.Save(&object).Error
|
||||
if err != nil {
|
||||
// User found
|
||||
@@ -154,3 +164,10 @@ func (u *User) IsStandardUser() bool {
|
||||
func ValidateRole(role string) bool {
|
||||
return role == RoleStandardUser || role == RoleMaintainer || role == RoleAdmin
|
||||
}
|
||||
|
||||
func (u *User) DisplayNameOrUsername() string {
|
||||
if strings.TrimSpace(u.DisplayName) != "" {
|
||||
return u.DisplayName
|
||||
}
|
||||
return u.Username
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user