fix: Open account login flow rework
This commit is contained in:
parent
2fd8f5d20b
commit
711f2d2e7b
1 changed files with 21 additions and 14 deletions
|
@ -100,26 +100,33 @@ 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()
|
||||||
err = scraper.Login(config.Username, config.Password)
|
if len(config.Username) > 0 {
|
||||||
if err != nil {
|
err = scraper.Login(config.Username, config.Password)
|
||||||
log.Printf("An error occurred during scraper login: %s\n", err.Error())
|
if err != nil {
|
||||||
|
log.Fatalf("An error occurred during scraper login: %s\n", err.Error())
|
||||||
|
} else {
|
||||||
|
log.Printf("New Login - Saving cookies to %s\n", cookiePath)
|
||||||
|
js, jsonErr := json.Marshal(scraper.GetCookies())
|
||||||
|
if jsonErr != nil {
|
||||||
|
log.Fatalf("An error occurred during cookie serialization: %s\n", jsonErr.Error())
|
||||||
|
}
|
||||||
|
f, fErr := os.Create(cookiePath)
|
||||||
|
if fErr != nil {
|
||||||
|
log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error())
|
||||||
|
}
|
||||||
|
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... ")
|
log.Println("Trying open account login... ")
|
||||||
err = scraper.LoginOpenAccount()
|
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()
|
defer scraper.Logout()
|
||||||
} else {
|
|
||||||
log.Printf("New Login - Saving cookies to %s\n", cookiePath)
|
|
||||||
js, jsonErr := json.Marshal(scraper.GetCookies())
|
|
||||||
if jsonErr != nil {
|
|
||||||
log.Fatalf("An error occurred during cookie serialization: %s\n", jsonErr.Error())
|
|
||||||
}
|
|
||||||
f, fErr := os.Create(cookiePath)
|
|
||||||
if fErr != nil {
|
|
||||||
log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error())
|
|
||||||
}
|
|
||||||
f.Write(js)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue