change occurences of 'code' to 'password'
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
| // This example shows you how to add, edit and remove port forwading entries. | // This example shows you how to add, edit and remove port forwading entries. | ||||||
| // Usage: cargo run --example port_forwards -- <Connect Box IP> <login code> <local IP> | // Usage: cargo run --example port_forwards -- <Connect Box IP> <login password> <local IP> | ||||||
|  |  | ||||||
| use std::{env, net::Ipv4Addr}; | use std::{env, net::Ipv4Addr}; | ||||||
|  |  | ||||||
| @@ -16,7 +16,7 @@ async fn main() -> Result<()> { | |||||||
|  |  | ||||||
|     let mut args = env::args().skip(1); |     let mut args = env::args().skip(1); | ||||||
|     let ip = args.next().expect("no ip specified"); |     let ip = args.next().expect("no ip specified"); | ||||||
|     let code = args.next().expect("no code specified"); |     let password = args.next().expect("no password specified"); | ||||||
|     let local_ip: Ipv4Addr = args |     let local_ip: Ipv4Addr = args | ||||||
|         .next() |         .next() | ||||||
|         .expect("no local ip specified") |         .expect("no local ip specified") | ||||||
| @@ -24,7 +24,7 @@ async fn main() -> Result<()> { | |||||||
|         .expect("local ip is not a valid ipv4 address"); |         .expect("local ip is not a valid ipv4 address"); | ||||||
|  |  | ||||||
|     // first, we create a new API client and log in to the router. |     // first, we create a new API client and log in to the router. | ||||||
|     let connect_box = ConnectBox::new(ip, code, true)?; |     let connect_box = ConnectBox::new(ip, password, true)?; | ||||||
|     connect_box.login().await?; |     connect_box.login().await?; | ||||||
|  |  | ||||||
|     // then, we remove all port forwarding entries for the local ip |     // then, we remove all port forwarding entries for the local ip | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ pub enum Error { | |||||||
|     #[error("session token not found, are you logged in?")] |     #[error("session token not found, are you logged in?")] | ||||||
|     NoSessionToken, |     NoSessionToken, | ||||||
|     #[error("incorrect password")] |     #[error("incorrect password")] | ||||||
|     IncorrectCode, |     IncorrectPassword, | ||||||
|     #[error("unexpected response from the server: {0:?}")] |     #[error("unexpected response from the server: {0:?}")] | ||||||
|     UnexpectedResponse(String), |     UnexpectedResponse(String), | ||||||
|     #[error("you are not logged in, or perhaps the session has expired")] |     #[error("you are not logged in, or perhaps the session has expired")] | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ type Field<'a, 'b> = (Cow<'a, str>, Cow<'b, str>); | |||||||
| /// The entry point of the library - the API client | /// The entry point of the library - the API client | ||||||
| pub struct ConnectBox { | pub struct ConnectBox { | ||||||
|     http: Client, |     http: Client, | ||||||
|     code: String, |     password: String, | ||||||
|     cookie_store: Arc<Jar>, |     cookie_store: Arc<Jar>, | ||||||
|     base_url: Url, |     base_url: Url, | ||||||
|     getter_url: Url, |     getter_url: Url, | ||||||
| @@ -36,9 +36,9 @@ pub struct ConnectBox { | |||||||
|  |  | ||||||
| impl ConnectBox { | impl ConnectBox { | ||||||
|     /// Create a new client associated with the specified address. You must call [`login`](Self::login()) before use. |     /// Create a new client associated with the specified address. You must call [`login`](Self::login()) before use. | ||||||
|     /// * `code` - the router password |     /// * `password` - the router password | ||||||
|     /// * `auto_reauth` - whether to automatically re-authenticate when the session expires |     /// * `auto_reauth` - whether to automatically re-authenticate when the session expires | ||||||
|     pub fn new(address: impl Display, code: String, auto_reauth: bool) -> Result<Self> { |     pub fn new(address: impl Display, password: String, auto_reauth: bool) -> Result<Self> { | ||||||
|         let cookie_store = Arc::new(Jar::default()); |         let cookie_store = Arc::new(Jar::default()); | ||||||
|         let http = Client::builder() |         let http = Client::builder() | ||||||
|             .user_agent("Mozilla/5.0") |             .user_agent("Mozilla/5.0") | ||||||
| @@ -50,7 +50,7 @@ impl ConnectBox { | |||||||
|         let setter_url = base_url.join("xml/setter.xml")?; |         let setter_url = base_url.join("xml/setter.xml")?; | ||||||
|         Ok(ConnectBox { |         Ok(ConnectBox { | ||||||
|             http, |             http, | ||||||
|             code, |             password, | ||||||
|             cookie_store, |             cookie_store, | ||||||
|             base_url, |             base_url, | ||||||
|             getter_url, |             getter_url, | ||||||
| @@ -139,7 +139,7 @@ impl ConnectBox { | |||||||
|             ("token".into(), session_token.into()), |             ("token".into(), session_token.into()), | ||||||
|             ("fun".into(), functions::LOGIN.to_string().into()), |             ("fun".into(), functions::LOGIN.to_string().into()), | ||||||
|             ("Username".into(), "NULL".into()), |             ("Username".into(), "NULL".into()), | ||||||
|             ("Password".into(), (&self.code).into()), |             ("Password".into(), (&self.password).into()), | ||||||
|         ]; |         ]; | ||||||
|         let req = self.http.post(self.setter_url.clone()).form(form); |         let req = self.http.post(self.setter_url.clone()).form(form); | ||||||
|         let resp = req.send().await?; |         let resp = req.send().await?; | ||||||
| @@ -155,7 +155,7 @@ impl ConnectBox { | |||||||
|         } |         } | ||||||
|         let resp_text = resp.text().await?; |         let resp_text = resp.text().await?; | ||||||
|         if resp_text == "idloginincorrect" { |         if resp_text == "idloginincorrect" { | ||||||
|             return Err(Error::IncorrectCode); |             return Err(Error::IncorrectPassword); | ||||||
|         } |         } | ||||||
|         let sid = resp_text |         let sid = resp_text | ||||||
|             .strip_prefix("successful;SID=") |             .strip_prefix("successful;SID=") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user