fix: Open account login flow rework

This commit is contained in:
Manuel 2023-10-17 00:05:00 +02:00
parent 2fd8f5d20b
commit 711f2d2e7b
Signed by: Manuel
GPG key ID: 4085037435E1F07A

View file

@ -100,15 +100,10 @@ func Run() {
log.Println("We're already logged in, skipping login...") log.Println("We're already logged in, skipping login...")
} else { } else {
scraper.ClearCookies() scraper.ClearCookies()
if len(config.Username) > 0 {
err = scraper.Login(config.Username, config.Password) err = scraper.Login(config.Username, config.Password)
if err != nil {
log.Printf("An error occurred during scraper login: %s\n", err.Error())
log.Println("Trying open account login... ")
err = scraper.LoginOpenAccount()
if err != nil { if err != nil {
log.Fatalf("An error occurred during scraper login: %s\n", err.Error()) log.Fatalf("An error occurred during scraper login: %s\n", err.Error())
}
defer scraper.Logout()
} else { } else {
log.Printf("New Login - Saving cookies to %s\n", cookiePath) log.Printf("New Login - Saving cookies to %s\n", cookiePath)
js, jsonErr := json.Marshal(scraper.GetCookies()) js, jsonErr := json.Marshal(scraper.GetCookies())
@ -120,6 +115,18 @@ func Run() {
log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error()) log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error())
} }
f.Write(js) f.Write(js)
writeErr := f.Close()
if writeErr != nil {
log.Fatalf("An error occurred on closing cookie file: %s\n", writeErr.Error())
}
}
} else {
log.Println("Trying open account login... ")
err = scraper.LoginOpenAccount()
if err != nil {
log.Fatalf("An error occurred during scraper login: %s\n", err.Error())
}
defer scraper.Logout()
} }
} }