team info
This commit is contained in:
30
klice.go
30
klice.go
@@ -117,13 +117,35 @@ func isLoggedIn(w http.ResponseWriter, r *http.Request) (bool, int) {
|
||||
|
||||
func teamInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if loggedIn, teamID := isLoggedIn(w, r); loggedIn {
|
||||
var teamName, city, last_cipher, penalty string
|
||||
err := db.QueryRow("SELECT name, city, last_cipher, penalty FROM teams WHERE id = ?", teamID).Scan(&teamName, &city, &last_cipher, &penalty)
|
||||
var teamName string
|
||||
var difficultyLevelID int
|
||||
var difficultyLevel string
|
||||
var lastCipher int
|
||||
var penalty int
|
||||
|
||||
err := db.QueryRow("SELECT name, difficulty_level, last_cipher, penalty FROM teams WHERE id = ?", teamID).Scan(&teamName, &difficultyLevelID, &lastCipher, &penalty)
|
||||
if err != nil {
|
||||
http.Error(w, "Could not retrieve team information", http.StatusInternalServerError)
|
||||
http.Error(w, "Could not retrieve team info", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = db.QueryRow("SELECT level_name FROM difficulty_levels WHERE id = ?", difficultyLevelID).Scan(&difficultyLevel)
|
||||
if err != nil {
|
||||
http.Error(w, "Could not retrieve difficulty level", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
TeamTemplateData := TeamTemplateS{
|
||||
TeamName: teamName,
|
||||
Difficulty: difficultyLevel,
|
||||
LastCipher: lastCipher,
|
||||
Penalties: penalty,
|
||||
}
|
||||
|
||||
err = TeamTemplate.Execute(w, TeamTemplateData)
|
||||
if err != nil {
|
||||
http.Error(w, "Could not render template", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "Team Name: %s, City: %s, Last Cipher: %s, Penalty: %s", teamName, city, last_cipher, penalty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,4 +15,12 @@ type CipherTemplateS struct {
|
||||
Wrong bool
|
||||
}
|
||||
|
||||
type TeamTemplateS struct {
|
||||
TeamName string
|
||||
Difficulty string
|
||||
LastCipher int
|
||||
Penalties int
|
||||
}
|
||||
|
||||
var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html"))
|
||||
var TeamTemplate = template.Must(template.ParseFiles("templates/team.html"))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="cs">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Zadání šifry {{.Order}}</title>
|
||||
</head>
|
||||
|
||||
|
||||
20
templates/team.html
Normal file
20
templates/team.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Tým: {{.TeamName}}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Tým: {{.TeamName}}</h1>
|
||||
Obtížnost: {{.Difficulty}}<br>
|
||||
Poslední šifra : {{.LastCipher}}<br>
|
||||
Penalizace: {{.Penalties}}<br>
|
||||
<hr>
|
||||
<form action="/logout" method="get">
|
||||
<input type="submit" value="Odhlásit">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user