Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add the stub AuthService.FindUserWithEmailAndPassword
天舟b7a2a110750e
diff --git a/backend/api/api.go b/backend/api/api.godeleted file mode 100644index d8dd0d7ae2..0000000000--- a/backend/api/api.go+++ /dev/null@@ -1,7 +0,0 @@-package api--import "github.com/labstack/echo/v4"--type Service interface {- RegisterRoutes(g *echo.Group)-}diff --git a/backend/api/auth.go b/backend/api/auth.goindex 92c6a22f76..43fb1ab5fc 100644--- a/backend/api/auth.go+++ b/backend/api/auth.go@@ -1,14 +1,10 @@package api-var (- _ AuthService = (*AuthService)(nil)-)-type Login struct {Email string `jsonapi:"attr,email"`Password string `jsonapi:"attr,password"`}type AuthService interface {- // FindUserWithEmailAndPassword(email string, password string) (*Principal, error)+ FindUserWithEmailAndPassword(email string, password string) (*Principal, error)}diff --git a/backend/api/environment.go b/backend/api/environment.goindex 29bc8f37d2..776dd98ad2 100644--- a/backend/api/environment.go+++ b/backend/api/environment.go@@ -1,9 +1,5 @@package api-var (- _ EnvironmentService = (*EnvironmentService)(nil)-)-type Environment struct {ID string `json:"id"`Name string `json:"name"`diff --git a/backend/api/principal.go b/backend/api/principal.gonew file mode 100644index 0000000000..7e281c9006--- /dev/null+++ b/backend/api/principal.go@@ -0,0 +1,6 @@+package api++type Principal struct {+ ID uint `jsonapi:"primary,principal"`+ Email string `jsonapi:"attr,email"`+}diff --git a/backend/cmd/server/bytebase.go b/backend/cmd/server/bytebase.goindex 0cb213b0d9..42bf1e8ce4 100644--- a/backend/cmd/server/bytebase.go+++ b/backend/cmd/server/bytebase.go@@ -32,6 +32,8 @@ func (m *Main) Run() error {return fmt.Errorf("cannot open db: %w", err)}+ m.server.AuthService = sqlite.NewAuthService(m.db)+if err := m.server.Run(); err != nil {return err}diff --git a/backend/server/auth.go b/backend/server/auth.goindex 0f3c42a7b5..4fcc9e5d94 100644--- a/backend/server/auth.go+++ b/backend/server/auth.go@@ -3,6 +3,7 @@ package serverimport ("net/http"+ "github.com/bytebase/bytebase""github.com/bytebase/bytebase/api""github.com/google/jsonapi""github.com/labstack/echo/v4"@@ -15,6 +16,14 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted login request")}+ _, err := s.AuthService.FindUserWithEmailAndPassword(login.Email, login.Password)+ if err != nil {+ if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {+ return echo.NewHTTPError(http.StatusUnauthorized)+ }+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process login request")+ }+c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)c.Response().WriteHeader(http.StatusOK)if err := jsonapi.MarshalPayload(c.Response().Writer, login); err != nil {diff --git a/backend/sqlite/auth.go b/backend/sqlite/auth.gonew file mode 100644index 0000000000..6f1694fe32--- /dev/null+++ b/backend/sqlite/auth.go@@ -0,0 +1,21 @@+package sqlite++import "github.com/bytebase/bytebase/api"++var (+ _ api.AuthService = (*AuthService)(nil)+)++// AuthService represents a service for managing auth.+type AuthService struct {+ db *DB+}++// NewAuthService returns a new instance of AuthService.+func NewAuthService(db *DB) *AuthService {+ return &AuthService{db: db}+}++func (s *AuthService) FindUserWithEmailAndPassword(email string, password string) (*api.Principal, error) {+ return &api.Principal{ID: 1, Email: "[email protected]"}, nil+}