feat: 添加用户认证服务,包括用户注册、登录、刷新令牌功能,并支持Gitee和GitHub OAuth认证。
This commit is contained in:
@@ -42,18 +42,20 @@ type GiteeTokenResponse struct {
|
||||
|
||||
// GiteeOAuthService handles Gitee OAuth operations
|
||||
type GiteeOAuthService struct {
|
||||
userRepo *repository.UserRepository
|
||||
authService *AuthService
|
||||
cfg *config.Config
|
||||
httpClient *http.Client
|
||||
userRepo *repository.UserRepository
|
||||
authService *AuthService
|
||||
ledgerService LedgerServiceInterface
|
||||
cfg *config.Config
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// NewGiteeOAuthService creates a new GiteeOAuthService instance
|
||||
func NewGiteeOAuthService(userRepo *repository.UserRepository, authService *AuthService, cfg *config.Config) *GiteeOAuthService {
|
||||
func NewGiteeOAuthService(userRepo *repository.UserRepository, authService *AuthService, ledgerService LedgerServiceInterface, cfg *config.Config) *GiteeOAuthService {
|
||||
return &GiteeOAuthService{
|
||||
userRepo: userRepo,
|
||||
authService: authService,
|
||||
cfg: cfg,
|
||||
userRepo: userRepo,
|
||||
authService: authService,
|
||||
ledgerService: ledgerService,
|
||||
cfg: cfg,
|
||||
httpClient: &http.Client{
|
||||
Timeout: 60 * time.Second,
|
||||
Transport: &http.Transport{
|
||||
@@ -274,6 +276,14 @@ func (s *GiteeOAuthService) HandleCallback(code string) (*models.User, *TokenPai
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Create default ledger for the new user
|
||||
_, err = s.ledgerService.CreateLedger(newUser.ID, LedgerInput{
|
||||
Name: "日常账本",
|
||||
Theme: "pink",
|
||||
IsDefault: true,
|
||||
SortOrder: 0,
|
||||
})
|
||||
|
||||
// Create OAuth account link
|
||||
oauth := &models.OAuthAccount{
|
||||
UserID: newUser.ID,
|
||||
|
||||
Reference in New Issue
Block a user