2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

feat: 添加翻译

This commit is contained in:
2025-04-12 18:41:08 +08:00
parent 3f90402164
commit 2d45e84b66
24 changed files with 267 additions and 223 deletions

View File

@@ -4,18 +4,21 @@ import (
"errors"
"github.com/go-rat/utils/hash"
"github.com/leonelquinteros/gotext"
"gorm.io/gorm"
"github.com/tnb-labs/panel/internal/biz"
)
type userRepo struct {
t *gotext.Locale
db *gorm.DB
hasher hash.Hasher
}
func NewUserRepo(db *gorm.DB) biz.UserRepo {
func NewUserRepo(t *gotext.Locale, db *gorm.DB) biz.UserRepo {
return &userRepo{
t: t,
db: db,
hasher: hash.NewArgon2id(),
}
@@ -42,14 +45,14 @@ func (r *userRepo) CheckPassword(username, password string) (*biz.User, error) {
user := new(biz.User)
if err := r.db.Where("username = ?", username).First(user).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("用户名或密码错误")
return nil, errors.New(r.t.Get("username or password error"))
} else {
return nil, err
}
}
if !r.hasher.Check(password, user.Password) {
return nil, errors.New("用户名或密码错误")
return nil, errors.New(r.t.Get("username or password error"))
}
return user, nil