|
|
|
|
@ -32,6 +32,12 @@ impl From<ReqwestError> for LoginError {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<serde_json::Error> for LoginError { |
|
|
|
|
fn from(_: serde_json::Error) -> Self { |
|
|
|
|
Self |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl HandleError for LoginError { |
|
|
|
|
fn handle_error(&self) { |
|
|
|
|
let error = i18n("Can’t login, try again"); |
|
|
|
|
@ -67,13 +73,15 @@ pub async fn login(
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let request = login_req(server, &body)?; |
|
|
|
|
let response: LoginResponse = HTTP_CLIENT |
|
|
|
|
let response_raw = HTTP_CLIENT |
|
|
|
|
.get_client() |
|
|
|
|
.execute(request) |
|
|
|
|
.await? |
|
|
|
|
.json() |
|
|
|
|
.bytes() |
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
let response: LoginResponse = serde_json::from_slice(&response_raw)?; |
|
|
|
|
|
|
|
|
|
if let (Some(tk), Some(uid)) = (response.access_token, response.user_id) { |
|
|
|
|
Ok((uid, tk, response.device_id)) |
|
|
|
|
} else { |
|
|
|
|
@ -104,6 +112,7 @@ pub async fn logout(server: Url, access_token: AccessToken) -> Result<(), Logout
|
|
|
|
|
#[derive(Debug)] |
|
|
|
|
pub enum GetWellKnownError { |
|
|
|
|
Reqwest(ReqwestError), |
|
|
|
|
Json(serde_json::Error), |
|
|
|
|
ParseUrl(UrlError), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -113,6 +122,12 @@ impl From<ReqwestError> for GetWellKnownError {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<serde_json::Error> for GetWellKnownError { |
|
|
|
|
fn from(err: serde_json::Error) -> Self { |
|
|
|
|
Self::Json(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<UrlError> for GetWellKnownError { |
|
|
|
|
fn from(err: UrlError) -> Self { |
|
|
|
|
Self::ParseUrl(err) |
|
|
|
|
@ -122,11 +137,12 @@ impl From<UrlError> for GetWellKnownError {
|
|
|
|
|
pub async fn get_well_known(domain: Url) -> Result<DomainInfoResponse, GetWellKnownError> { |
|
|
|
|
let request = domain_info(domain)?; |
|
|
|
|
|
|
|
|
|
HTTP_CLIENT |
|
|
|
|
let response_raw = HTTP_CLIENT |
|
|
|
|
.get_client() |
|
|
|
|
.execute(request) |
|
|
|
|
.await? |
|
|
|
|
.json() |
|
|
|
|
.await |
|
|
|
|
.map_err(Into::into) |
|
|
|
|
.bytes() |
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
serde_json::from_slice(&response_raw).map_err(Into::into) |
|
|
|
|
} |
|
|
|
|
|