feat: 환경변수로 초기 admin 계정 자동 생성
서버 시작 시 ADMIN_USERNAME, ADMIN_PASSWORD 환경변수 기반으로 admin 계정이 없을 경우 자동 생성 (이미 있으면 스킵) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -64,3 +64,18 @@ func (s *Service) Logout(userID uint) {
|
||||
key := fmt.Sprintf("session:%d", userID)
|
||||
s.rdb.Del(context.Background(), key)
|
||||
}
|
||||
|
||||
func (s *Service) EnsureAdmin(username, password string) error {
|
||||
if _, err := s.repo.FindByUsername(username); err == nil {
|
||||
return nil // 이미 존재하면 스킵
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.Create(&User{
|
||||
Username: username,
|
||||
PasswordHash: string(hash),
|
||||
Role: RoleAdmin,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user