Export user credential by contest ID

This commit is contained in:
Andrea Fazzi 2023-05-03 16:19:53 +02:00
parent 9bb73c6059
commit 314603db64
3 changed files with 30 additions and 9 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
*~ *~
oef oef
**/*.xlsx
**/*.ods

View file

@ -20,6 +20,7 @@ func main() {
username := flag.String("username", "admin", "Username") username := flag.String("username", "admin", "Username")
password := flag.String("password", "admin", "Password") password := flag.String("password", "admin", "Password")
output := flag.String("output", "credentials.csv", "Output filename") output := flag.String("output", "credentials.csv", "Output filename")
cid := flag.Uint("cid", 0, "Export credentials of participants subscribed to the given contest")
flag.Parse() flag.Parse()
@ -38,11 +39,28 @@ func main() {
panic(err) panic(err)
} }
if *cid != 0 {
log.Printf("Get participants subscribed to contest ID %v", *cid)
contest := new(orm.Contest)
contest.ID = *cid
_, err := client.Read(contest)
if err != nil {
panic(err)
}
for _, participant := range contest.Participants {
for _, user := range users {
if user.ID == participant.UserID {
credentials = append(credentials, &Credential{user.ID, user.Username, user.Password})
}
}
}
} else {
for _, user := range users { for _, user := range users {
if user.Role == "participant" { if user.Role == "participant" {
credentials = append(credentials, &Credential{user.ID, user.Username, user.Password}) credentials = append(credentials, &Credential{user.ID, user.Username, user.Password})
} }
} }
}
f, err := os.Create(*output) f, err := os.Create(*output)
if err != nil { if err != nil {

View file

@ -1,19 +1,19 @@
contests: contests:
- id: 22 - id: 30
category: Junior category: Junior
regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto] regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto]
- id: 23 - id: 31
category: Senior category: Senior
regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto] regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto]
- id: 26 - id: 32
category: Junior category: Junior
regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige] regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige]
- id: 27 - id: 33
category: Senior category: Senior
regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige] regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige]
- id: 28 - id: 34
category: Junior category: Junior
regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria] regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria]
- id: 25 - id: 35
category: Senior category: Senior
regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria] regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria]