Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1750-fresh-setup-msg'
Browse files Browse the repository at this point in the history
# Conflicts:
#	deepfence_server/model/user.go
  • Loading branch information
ramanan-ravi committed Nov 30, 2023
2 parents 6b4c8e5 + f52c3e2 commit 3e1653d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions deepfence_server/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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)

Check failure on line 161 in deepfence_server/handler/auth.go

View workflow job for this annotation

GitHub Actions / lint-server

ST1005: error strings should not be capitalized (stylecheck)
return
}
u, statusCode, pgClient, err := model.GetUserByEmail(ctx, loginRequest.Email)
if err != nil {
h.respondWithErrorCode(err, w, statusCode)
Expand Down
12 changes: 12 additions & 0 deletions deepfence_server/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ 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
}
return uc == 0, 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

0 comments on commit 3e1653d

Please sign in to comment.