logonCurl :: YukariSettings -> IO Curl
logonCurl ys = do
  let s = ys ^. siteSettings
  b <- banned s
  when b $ do
    putStrLn "Seems you have been banned from logging in. Check the site."
    exitFailure

  let fields = CurlPostFields [ "username=" ++ s ^. username
                              , "password=" ++ s ^. password ] : method_POST
  curl <- initialize
  setopts curl [ CurlCookieJar "cookies", CurlUserAgent defaultUserAgent
               , CurlTimeout 15 ]
  r <- do_curl_ curl (s ^. loginSite) fields :: IO CurlResponse
  l <- loggedIn ys curl
  if respCurlCode r /= CurlOK || not l
    then error $ concat ["Failed to log in as ", s ^. username, ": "
                        , show $ respCurlCode r, " -- ", respStatusLine r]
    else return curl

-- | Crawl the page according to user settings and using a specified curl
-- session. We can obtain the appropiate session using 'logonCurl'.
logonCurl :: YukariSettings -> IO Curl
logonCurl ys = do
  let s = ys ^. siteSettings
  b <- banned s
  when b $ do
    putStrLn "Seems you have been banned from logging in. Check the site."
    exitFailure

  let fields = CurlPostFields [ "username=" ++ s ^. username
                              , "password=" ++ s ^. password ] : method_POST
  curl <- initialize
  setopts curl [ CurlCookieJar "cookies", CurlUserAgent defaultUserAgent
               , CurlTimeout 15 ]
  r <- do_curl_ curl (s ^. loginSite) fields :: IO CurlResponse
  l <- loggedIn ys curl
  if respCurlCode r /= CurlOK || not l
    then error $ concat ["Failed to log in as ", s ^. username, ": "
                        , show $ respCurlCode r, " -- ", respStatusLine r]
    else return curl

-- | Crawl the page according to user settings and using a specified curl
-- session. We can obtain the appropiate session using 'logonCurl'.
logonCurl ys = do
  let s = ys ^. siteSettings
  b <- banned s
  when b $ do
    putStrLn "Seems you have been banned from logging in. Check the site."
    exitFailure

  let fields = CurlPostFields [ "username=" ++ s ^. username
                              , "password=" ++ s ^. password ] : method_POST
  curl <- initialize
  setopts curl [ CurlCookieJar "cookies", CurlUserAgent defaultUserAgent
               , CurlTimeout 15 ]
  r <- do_curl_ curl (s ^. loginSite) fields :: IO CurlResponse
  l <- loggedIn ys curl
  if respCurlCode r /= CurlOK || not l
    then error $ concat ["Failed to log in as ", s ^. username, ": "
                        , show $ respCurlCode r, " -- ", respStatusLine r]
    else return curl

-- | Crawl the page according to user settings and using a specified curl
-- session. We can obtain the appropiate session using 'logonCurl'.