Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For new installation show message in UI #1785

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions deepfence_server/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ func (h *Handler) LoginHandler(w http.ResponseWriter, r *http.Request) {
}
loginRequest.Email = strings.ToLower(loginRequest.Email)
ctx := directory.NewContextWithNameSpace(directory.FetchNamespace(loginRequest.Email))

// if it is a fresh setup, there won't be any users in the system
freshSetup, err := model.IsFreshSetup(ctx)
if err != nil {
h.respondError(err, w)
return
}
if freshSetup {
h.respondError(&NotFoundError{errors.New("For a new console installation, registration by the user is required")}, w)
return
}
u, statusCode, pgClient, err := model.GetUserByEmail(ctx, loginRequest.Email)
if err != nil {
h.respondWithErrorCode(err, w, statusCode)
Expand Down
15 changes: 15 additions & 0 deletions deepfence_server/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ func GetUserByEmail(ctx context.Context, email string) (*User, int, *postgresqlD
return &user, http.StatusOK, pgClient, nil
}

func IsFreshSetup(ctx context.Context) (bool, error) {
pgClient, err := directory.PostgresClient(ctx)
if err != nil {
return false, err
}
uc, err := pgClient.CountUsers(ctx)
if err != nil {
return false, err
}
if uc == 0 {
return true, nil
}
return false, nil
}

func (u *User) LoadFromDbByEmail(ctx context.Context, pgClient *postgresqlDb.Queries) error {
// Set email field and load other fields from db
var err error
Expand Down