Skip to content

Commit

Permalink
Fix FixUsername to fix usernames :)
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wregglesworth committed Sep 12, 2024
1 parent 03c50ac commit d092903
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strings"
"regexp"

"github.com/cyverse-de/go-mod/logging"
"github.com/cyverse-de/go-mod/pbinit"
Expand Down Expand Up @@ -89,17 +89,12 @@ func New(client *natscl.Client, db *sqlx.DB, userSuffix string) *App {
}

func (a *App) FixUsername(username string) (string, error) {
var trimSuffix string
if strings.HasPrefix(a.userSuffix, "@") {
trimSuffix = a.userSuffix
} else {
trimSuffix = fmt.Sprintf("@%s", a.userSuffix)
}
u := strings.TrimSuffix(username, trimSuffix)
if u == "" {
return "", errors.ErrInvalidUsername

re, err := regexp.Compile(`@.*$`)
if err != nil {
return "", err
}
return u, nil
return re.ReplaceAllString(username, ""), nil
}

func (a *App) validateUpdate(request *qms.AddUpdateRequest) (string, error) {
Expand Down

0 comments on commit d092903

Please sign in to comment.