Spaces:
Running
Running
Upload main.rs
Browse files- src/main.rs +53 -16
src/main.rs
CHANGED
|
@@ -1376,6 +1376,21 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
|
|
| 1376 |
return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
|
| 1377 |
}
|
| 1378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1379 |
match mobile_login(&email, &pass).await {
|
| 1380 |
Ok(arl) => (StatusCode::OK, Json(json!({
|
| 1381 |
"arl": arl,
|
|
@@ -1390,18 +1405,19 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
|
|
| 1390 |
"uid": "",
|
| 1391 |
"access_token": null
|
| 1392 |
}))).into_response(),
|
| 1393 |
-
Err(e2) =>
|
| 1394 |
-
|
| 1395 |
-
|
| 1396 |
-
|
| 1397 |
-
|
| 1398 |
-
|
| 1399 |
-
}
|
| 1400 |
-
|
| 1401 |
-
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
|
|
|
| 1405 |
}
|
| 1406 |
}
|
| 1407 |
}
|
|
@@ -1766,14 +1782,35 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
|
|
| 1766 |
|
| 1767 |
let pass_md5 = format!("{:x}", md5::compute(password.as_bytes()));
|
| 1768 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1769 |
let res = match mobile_login(&email, &pass_md5).await {
|
| 1770 |
Ok(arl) => Ok(arl),
|
| 1771 |
Err(e1) => match web_login(&email, &pass_md5).await {
|
| 1772 |
Ok(arl) => Ok(arl),
|
| 1773 |
-
Err(e2) =>
|
| 1774 |
-
|
| 1775 |
-
|
| 1776 |
-
|
|
|
|
|
|
|
|
|
|
| 1777 |
},
|
| 1778 |
};
|
| 1779 |
|
|
|
|
| 1376 |
return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
|
| 1377 |
}
|
| 1378 |
|
| 1379 |
+
let mut worker_err: Option<String> = None;
|
| 1380 |
+
if worker_base().is_some() {
|
| 1381 |
+
match worker_login(&email, &pass).await {
|
| 1382 |
+
Ok(arl) => {
|
| 1383 |
+
return (StatusCode::OK, Json(json!({
|
| 1384 |
+
"arl": arl,
|
| 1385 |
+
"token": null,
|
| 1386 |
+
"uid": "",
|
| 1387 |
+
"access_token": null
|
| 1388 |
+
}))).into_response();
|
| 1389 |
+
}
|
| 1390 |
+
Err(e) => worker_err = Some(e),
|
| 1391 |
+
}
|
| 1392 |
+
}
|
| 1393 |
+
|
| 1394 |
match mobile_login(&email, &pass).await {
|
| 1395 |
Ok(arl) => (StatusCode::OK, Json(json!({
|
| 1396 |
"arl": arl,
|
|
|
|
| 1405 |
"uid": "",
|
| 1406 |
"access_token": null
|
| 1407 |
}))).into_response(),
|
| 1408 |
+
Err(e2) => {
|
| 1409 |
+
if let Some(e0) = worker_err {
|
| 1410 |
+
json_error(
|
| 1411 |
+
StatusCode::UNAUTHORIZED,
|
| 1412 |
+
format!("login_failed; worker:{e0}; mobile:{e1}; web:{e2}"),
|
| 1413 |
+
)
|
| 1414 |
+
} else {
|
| 1415 |
+
json_error(
|
| 1416 |
+
StatusCode::UNAUTHORIZED,
|
| 1417 |
+
format!("login_failed; mobile:{e1}; web:{e2}; worker:worker:disabled"),
|
| 1418 |
+
)
|
| 1419 |
+
}
|
| 1420 |
+
}
|
| 1421 |
}
|
| 1422 |
}
|
| 1423 |
}
|
|
|
|
| 1782 |
|
| 1783 |
let pass_md5 = format!("{:x}", md5::compute(password.as_bytes()));
|
| 1784 |
|
| 1785 |
+
let mut worker_err: Option<String> = None;
|
| 1786 |
+
if worker_base().is_some() {
|
| 1787 |
+
match worker_login(&email, &pass_md5).await {
|
| 1788 |
+
Ok(arl) => {
|
| 1789 |
+
let mut map = state.pair.write().await;
|
| 1790 |
+
if let Some(s) = map.get_mut(&code) {
|
| 1791 |
+
s.arl = Some(arl);
|
| 1792 |
+
s.email = Some(email);
|
| 1793 |
+
s.error = None;
|
| 1794 |
+
}
|
| 1795 |
+
drop(map);
|
| 1796 |
+
pair_store_save(&state).await;
|
| 1797 |
+
return Html("<h3>Готово</h3><p>Вернись на ТВ — плагин подключится автоматически.</p>".to_string()).into_response();
|
| 1798 |
+
}
|
| 1799 |
+
Err(e) => worker_err = Some(e),
|
| 1800 |
+
}
|
| 1801 |
+
}
|
| 1802 |
+
|
| 1803 |
let res = match mobile_login(&email, &pass_md5).await {
|
| 1804 |
Ok(arl) => Ok(arl),
|
| 1805 |
Err(e1) => match web_login(&email, &pass_md5).await {
|
| 1806 |
Ok(arl) => Ok(arl),
|
| 1807 |
+
Err(e2) => {
|
| 1808 |
+
if let Some(e0) = worker_err {
|
| 1809 |
+
Err(format!("worker:{e0}; mobile:{e1}; web:{e2}"))
|
| 1810 |
+
} else {
|
| 1811 |
+
Err(format!("mobile:{e1}; web:{e2}; worker:worker:disabled"))
|
| 1812 |
+
}
|
| 1813 |
+
}
|
| 1814 |
},
|
| 1815 |
};
|
| 1816 |
|