Add monorepo structure for NexaVPN WireGuard control plane including: - .gitignore for node_modules, build artifacts, and environment files - README with project overview, monorepo layout, and quick start guide - Admin web UI with React, Vite, TypeScript, and nginx reverse proxy - API client with type definitions for users, devices, policies, gateways, and audit logs - Admin pages for dashboard, users, devices, policies, g
38 lines
749 B
Go
38 lines
749 B
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nexavpn/nexavpn/backend/internal/auth"
|
|
)
|
|
|
|
type Service struct {
|
|
repo Repository
|
|
}
|
|
|
|
func NewService(repo Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) List(ctx context.Context) ([]User, error) {
|
|
return s.repo.List(ctx)
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, input CreateRequest) (User, error) {
|
|
passwordHash, err := auth.HashPassword(input.Password)
|
|
if err != nil {
|
|
return User{}, err
|
|
}
|
|
return s.repo.Create(ctx, input, passwordHash)
|
|
}
|
|
|
|
func (s *Service) SetActive(ctx context.Context, userID string, active bool) error {
|
|
id, err := uuid.Parse(userID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return s.repo.SetActive(ctx, id, active)
|
|
}
|