diff --git a/assets/templates/form.tmpl b/assets/templates/form.tmpl index 5eb300e26092baa82839f88cc707ed21d4ba182d..046758de2345890f12a740329814c114f8ccbcb5 100644 --- a/assets/templates/form.tmpl +++ b/assets/templates/form.tmpl @@ -66,6 +66,13 @@ </label> </div> {{ end }} + {{if .team_size.E}} + <div class="col-md-6"> + <label> + <input type="text" placeholder="Player 5 Name + UID" name="Player4"> + </label> + </div> + {{ end }} </div> <button>Gönder</button> </form> diff --git a/routes.go b/routes.go index 88a7d685f16d695021cfbe5d637550ba36fab4d6..96b2ada7e0d5b41483d5088b72166015dc3af338 100644 --- a/routes.go +++ b/routes.go @@ -13,7 +13,7 @@ import ( func registerRoutes() { router.GET("/", func(context *gin.Context) { - authText, authRef := getAuthButton(oauth.GetSelf(context)) + authText, authRef := getAuthButton(oauth.GetSelf(context), true) if ts, err := getTournaments(); err != nil { log.Printf("error retrieving tournaments: %s", err) context.String(http.StatusInternalServerError, "Internal Server Error") @@ -54,7 +54,7 @@ func registerRoutes() { return } - authText, authRef := getAuthButton(user) + authText, authRef := getAuthButton(user, false) var tsn int if n, err := strconv.Atoi(t.Attributes["size"]); err != nil { @@ -62,13 +62,14 @@ func registerRoutes() { context.String(http.StatusInternalServerError, "Internal Server Error") return } else { - tsn = n + tsn = n + 1 } ts := struct { A bool B bool C bool D bool + E bool }{} if tsn > 0 { ts.A = true @@ -82,6 +83,9 @@ func registerRoutes() { if tsn > 3 { ts.D = true } + if tsn > 4 { + ts.E = true + } sy, sm, sd := t.StartTime.Date() dy, dm, dd := t.Deadline.Date() @@ -132,7 +136,7 @@ func registerRoutes() { context.String(http.StatusInternalServerError, "Internal Server Error") return } else { - tsn = n + tsn = n + 1 } team := bindEnrollment(context, user, tsn) @@ -162,7 +166,7 @@ func registerRoutes() { return } - authText, authRef := getAuthButton(user) + authText, authRef := getAuthButton(user, true) if t, err := getTournaments(); err != nil { log.Printf("error retrieving tournaments: %s", err) @@ -190,7 +194,7 @@ func registerRoutes() { return } - authText, authRef := getAuthButton(user) + authText, authRef := getAuthButton(user, true) context.HTML(http.StatusOK, "tournament-config.tmpl", gin.H{ "auth_text": authText, @@ -240,7 +244,7 @@ func registerRoutes() { return } - authText, authRef := getAuthButton(user) + authText, authRef := getAuthButton(user, true) sy, sm, sd := t.StartTime.Date() dy, dm, dd := t.Deadline.Date() diff --git a/tournament.go b/tournament.go index b5f90d86dbe71a6cedb36e4ddc7663fc5068cb76..bc43a726b8c44c689c0b3023ef4b868e7d5d92f8 100644 --- a/tournament.go +++ b/tournament.go @@ -322,8 +322,8 @@ func csvTournament(t uuid.UUID) ([]byte, error) { records[0][2] = "Submitter Discord ID" records[0][3] = "Submitter First Name" records[0][4] = "Submitter Last Name" - for i := 3; i < width; i++ { - records[0][i] = fmt.Sprintf("Member %d", i-2) + for i := 5; i < width; i++ { + records[0][i] = fmt.Sprintf("Member %d", i-4) } for i, team := range teams { diff --git a/user.go b/user.go index ae0ff073b527e8450bf95028bc37c9330022f576..7445463114f77547dbc0a47308143c3214db4fa5 100644 --- a/user.go +++ b/user.go @@ -12,6 +12,8 @@ import ( "sync" ) +const clickToLogout = " (Click to log out)" + type userEnrollment struct { TeamName string FirstName string @@ -21,6 +23,7 @@ type userEnrollment struct { Player1 string Player2 string Player3 string + Player4 string } type teamPayload struct { @@ -208,11 +211,14 @@ func getTournamentTeam(t uuid.UUID) ([]string, error) { } } -func getAuthButton(user *discordgo.User) (authText, authRef string) { +func getAuthButton(user *discordgo.User, logout bool) (authText, authRef string) { authText = "Login" authRef = "/auth/login" if user != nil { - authText = user.Username + " (Click to log out)" + authText = user.Username + if logout { + authText += clickToLogout + } authRef = "/auth/logout" } return @@ -225,7 +231,8 @@ func validateEnrollment(payload *userEnrollment) bool { len(payload.Player0) <= 64 && len(payload.Player1) <= 64 && len(payload.Player2) <= 64 && - len(payload.Player3) <= 64 + len(payload.Player3) <= 64 && + len(payload.Player4) <= 64 } func bindEnrollment(context *gin.Context, user *discordgo.User, tsn int) *teamPayload { @@ -286,6 +293,14 @@ func bindEnrollment(context *gin.Context, user *discordgo.User, tsn int) *teamPa return nil } } + if tsn > 4 { + if len(payload.Player4) > 0 { + players[4] = payload.Player4 + } else { + context.String(http.StatusBadRequest, "Bad Request") + return nil + } + } return &teamPayload{ Name: payload.TeamName,