2021-04-28 12:52:25 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2021-04-28 13:29:45 +02:00
|
|
|
"fmt"
|
2021-04-28 12:52:25 +02:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"git.andreafazzi.eu/andrea/oef/client"
|
|
|
|
"git.andreafazzi.eu/andrea/oef/orm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func login(url string, user *orm.User) error {
|
|
|
|
log.Printf("Obtaining token for user %s (%s %s)", user, user.Username, user.Password)
|
|
|
|
_, err := client.GetToken(url, user.Username, user.Password)
|
|
|
|
if err != nil {
|
2021-04-28 13:29:45 +02:00
|
|
|
return fmt.Errorf("An error occurred for user %s", user)
|
2021-04-28 12:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
username := flag.String("username", "admin", "Username")
|
|
|
|
password := flag.String("password", "admin", "Password")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
client, err := client.Dial(flag.Arg(0), *username, *password)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
users := make([]*orm.User, 0)
|
|
|
|
|
|
|
|
log.Println("Get all users...")
|
|
|
|
err = client.ReadAll(&users)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, user := range users {
|
2021-04-28 13:29:45 +02:00
|
|
|
err := login(flag.Arg(0), user)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-04-28 12:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|