Enhance user authentication and authentication

Fix the modification of personal information
Fix the formatted page template
This commit is contained in:
2025-10-26 03:05:27 +08:00
parent 3e170ad526
commit c93ee377fe
22 changed files with 2728 additions and 2420 deletions

View File

@@ -8,21 +8,22 @@ import (
)
// SeedDefaultAdmin 初始化默认管理员账号
// - 如果用户名为 admin 的用户已存在,则跳过
// - 如果已存在任何管理员用户role=0,则跳过
// - 如不存在,则创建用户名为 admin、密码为 admin123以 bcrypt 哈希存储)、角色 Role=0 的管理员
// - ID和UUID将自动生成
// - 根据需求:默认 admin 用户的 ID 固定为 10000
func SeedDefaultAdmin() error {
db, err := GetDB()
if err != nil {
return err
}
// 检查是否存在用户名为 admin 的用户
// 检查是否存在任何管理员用户role=0
var count int64
if dbErr := db.Model(&models.User{}).Where("username = ?", "admin").Count(&count).Error; dbErr != nil {
if dbErr := db.Model(&models.User{}).Where("role = ?", 0).Count(&count).Error; dbErr != nil {
return dbErr
}
if count > 0 {
logrus.Info("已存在管理员用户,跳过默认管理员创建")
return nil
}