feat: 管理后台登录
Some checks failed
Backend Deploy (Go + Docker) / deploy (push) Successful in 1m4s
Extension Build & Release / build (push) Failing after 46s

This commit is contained in:
zs
2026-03-02 23:54:59 +08:00
parent 4e5147fb13
commit d2b330c0c9
7 changed files with 115 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package service
import (
"github.com/zs/InsightReply/internal/model"
"github.com/zs/InsightReply/internal/repository"
"golang.org/x/crypto/bcrypt"
)
type UserService struct {
@@ -13,12 +14,18 @@ func NewUserService(repo *repository.UserRepository) *UserService {
return &UserService{repo: repo}
}
func (s *UserService) Register(email string, identity string) (*model.User, error) {
func (s *UserService) Register(email string, password string, identity string) (*model.User, error) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return nil, err
}
user := &model.User{
Email: email,
PasswordHash: string(hashedPassword),
IdentityLabel: identity,
}
err := s.repo.Create(user)
err = s.repo.Create(user)
return user, err
}