Skip to content

Commit 13e1f9e

Browse files
intojhanuragbupd
andauthored
fix(member): add username validation in member creation view (#615)
Co-authored-by: bupd <bupdprasanth@gmail.com>
1 parent 1b92e07 commit 13e1f9e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/views/member/create/view.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/charmbracelet/huh"
2222
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
23+
"github.com/goharbor/harbor-cli/pkg/utils"
2324
)
2425

2526
type MemberUser struct {
@@ -85,9 +86,13 @@ func CreateMemberView(createView *CreateView) {
8586
huh.NewInput().
8687
Title("Username").
8788
Value(&createView.MemberUser.Username).
88-
Validate(func(str string) error { // TODO: Add username checking
89+
Validate(func(str string) error {
8990
if str == "" {
90-
return errors.New("Username and UserID cannot both be empty.")
91+
return errors.New("Username cannot be empty.")
92+
}
93+
94+
if !utils.ValidateUserName(str) {
95+
return errors.New("Invalid username. Must be 1-255 characters long and cannot contain special characters: , \" ~ # % $")
9196
}
9297

9398
return nil

0 commit comments

Comments
 (0)