aboutsummaryrefslogtreecommitdiff
path: root/src/orly.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-02-11 11:13:36 +0300
committerA Farzat <a@farzat.xyz>2026-02-11 11:13:36 +0300
commit2d9314aa3145ec7948341f38164e13c2a2d945ad (patch)
tree29f69a0b89983fbeb2f0227698aab9dd884d9a54 /src/orly.rs
parent3321918c009e9d7a7a3c3c2a1f490bb91fefb2bc (diff)
downloadsafaribooks-rs-2d9314aa3145ec7948341f38164e13c2a2d945ad.tar.gz
safaribooks-rs-2d9314aa3145ec7948341f38164e13c2a2d945ad.zip
Add a login check
Try to access the profile page to see if the cookies work or not.
Diffstat (limited to 'src/orly.rs')
-rw-r--r--src/orly.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/orly.rs b/src/orly.rs
new file mode 100644
index 0000000..cd8b645
--- /dev/null
+++ b/src/orly.rs
@@ -0,0 +1,22 @@
+use crate::http_client::HttpClient;
+use anyhow::{bail, Result};
+
+pub const PROFILE_URL: &str = "https://learning.oreilly.com/profile/";
+
+/// Check whether cookies keep us logged in by fetching the profile page.
+/// Returns:
+/// - Ok(true) => HTTP 200 (assume logged in)
+/// - Ok(false) => Redirect or 401/403 (assume not logged in)
+/// - Err(..) => Network/other error
+pub async fn check_login(client: &HttpClient) -> Result<bool> {
+ let res = client.client().get(PROFILE_URL).send().await?;
+ let status = res.status();
+
+ if status.is_redirection() {
+ Ok(false)
+ } else if status == 200 {
+ Ok(true)
+ } else {
+ bail!("Profile request returned unexpected status {}", status)
+ }
+}