recycleactor commited on
Commit
46efca0
·
verified ·
1 Parent(s): 3d8ea87

Upload main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +51 -40
src/main.rs CHANGED
@@ -1086,6 +1086,18 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1086
  .build()
1087
  .unwrap();
1088
 
 
 
 
 
 
 
 
 
 
 
 
 
1089
  let mut gw_token: Option<String> = None;
1090
  let mut gw_uid: Option<String> = None;
1091
  let mut arl_out: Option<String> = None;
@@ -1097,7 +1109,6 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1097
  if token.is_empty() {
1098
  gw_err = Some("gw:no_checkForm".to_string());
1099
  } else {
1100
- gw_token = Some(token.clone());
1101
  gw_uid = ud["USER"]["USER_ID"]
1102
  .as_i64()
1103
  .map(|n| n.to_string())
@@ -1116,13 +1127,18 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1116
  )
1117
  .await
1118
  {
1119
- return json_error(StatusCode::UNAUTHORIZED, e);
1120
- }
 
 
 
 
1121
 
1122
- if let Ok(v) = gw_light_call(&client, &jar, "user.getArl", &token, json!({})).await {
1123
- if let Some(s) = v.as_str() {
1124
- if s.len() > 20 {
1125
- arl_out = Some(s.to_string());
 
1126
  }
1127
  }
1128
  }
@@ -1133,18 +1149,6 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
1133
  }
1134
  }
1135
 
1136
- let mut access_token_out: Option<String> = None;
1137
- let mut oauth_uid: Option<String> = None;
1138
- if let Ok(access_token) = oauth_access_token(&client, &email, &pass).await {
1139
- oauth_uid = api_deezer_get(&client, "/user/me", &access_token, &[])
1140
- .await
1141
- .ok()
1142
- .and_then(|v| v.get("id").and_then(|x| x.as_i64()))
1143
- .filter(|id| *id > 0)
1144
- .map(|id| id.to_string());
1145
- access_token_out = Some(access_token);
1146
- }
1147
-
1148
  let uid_out = gw_uid.or(oauth_uid).unwrap_or_default();
1149
 
1150
  if gw_token.is_none() && access_token_out.is_none() {
@@ -1373,6 +1377,11 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
1373
  let mut gw_uid: Option<String> = None;
1374
  let mut arl_out: Option<String> = None;
1375
  let mut access_token_out: Option<String> = None;
 
 
 
 
 
1376
 
1377
  if let Ok(ud) = gw_light_call(&client, &jar, "deezer.getUserData", "null", json!({})).await {
1378
  let token = ud["checkForm"].as_str().unwrap_or("").to_string();
@@ -1390,36 +1399,38 @@ async fn pair_complete(State(state): State<AppState>, Form(f): Form<PairComplete
1390
  )
1391
  .await
1392
  {
1393
- let mut map = state.pair.write().await;
1394
- if let Some(s) = map.get_mut(&code) {
1395
- s.error = Some(format!("gw:checkCredentials:{e}"));
1396
- }
1397
- return Html(format!("<h3>Ошибка входа</h3><pre>{}</pre>", htmlesc(&format!("gw:checkCredentials:{e}"))))
 
 
 
 
1398
  .into_response();
1399
- }
1400
-
1401
- gw_token = Some(token.clone());
1402
- gw_uid = ud["USER"]["USER_ID"]
1403
- .as_i64()
1404
- .map(|n| n.to_string())
1405
- .filter(|s| !s.trim().is_empty());
 
1406
 
1407
- if let Ok(v) = gw_light_call(&client, &jar, "user.getArl", &token, json!({})).await {
1408
- if let Some(s) = v.as_str() {
1409
- if s.len() > 20 {
1410
- arl_out = Some(s.to_string());
 
1411
  }
1412
  }
1413
  }
1414
  }
1415
  }
1416
 
1417
- if let Ok(t) = oauth_access_token(&client, &email, &pass_md5).await {
1418
- access_token_out = Some(t);
1419
- }
1420
-
1421
  if gw_token.is_none() && access_token_out.is_none() {
1422
- let msg = "login_failed".to_string();
1423
  let mut map = state.pair.write().await;
1424
  if let Some(s) = map.get_mut(&code) {
1425
  s.error = Some(msg.clone());
 
1086
  .build()
1087
  .unwrap();
1088
 
1089
+ let mut access_token_out: Option<String> = None;
1090
+ let mut oauth_uid: Option<String> = None;
1091
+ if let Ok(access_token) = oauth_access_token(&client, &email, &pass).await {
1092
+ oauth_uid = api_deezer_get(&client, "/user/me", &access_token, &[])
1093
+ .await
1094
+ .ok()
1095
+ .and_then(|v| v.get("id").and_then(|x| x.as_i64()))
1096
+ .filter(|id| *id > 0)
1097
+ .map(|id| id.to_string());
1098
+ access_token_out = Some(access_token);
1099
+ }
1100
+
1101
  let mut gw_token: Option<String> = None;
1102
  let mut gw_uid: Option<String> = None;
1103
  let mut arl_out: Option<String> = None;
 
1109
  if token.is_empty() {
1110
  gw_err = Some("gw:no_checkForm".to_string());
1111
  } else {
 
1112
  gw_uid = ud["USER"]["USER_ID"]
1113
  .as_i64()
1114
  .map(|n| n.to_string())
 
1127
  )
1128
  .await
1129
  {
1130
+ if access_token_out.is_none() {
1131
+ return json_error(StatusCode::UNAUTHORIZED, format!("gw:checkCredentials:{e}"));
1132
+ }
1133
+ gw_err = Some(format!("gw:checkCredentials:{e}"));
1134
+ } else {
1135
+ gw_token = Some(token.clone());
1136
 
1137
+ if let Ok(v) = gw_light_call(&client, &jar, "user.getArl", &token, json!({})).await {
1138
+ if let Some(s) = v.as_str() {
1139
+ if s.len() > 20 {
1140
+ arl_out = Some(s.to_string());
1141
+ }
1142
  }
1143
  }
1144
  }
 
1149
  }
1150
  }
1151
 
 
 
 
 
 
 
 
 
 
 
 
 
1152
  let uid_out = gw_uid.or(oauth_uid).unwrap_or_default();
1153
 
1154
  if gw_token.is_none() && access_token_out.is_none() {
 
1377
  let mut gw_uid: Option<String> = None;
1378
  let mut arl_out: Option<String> = None;
1379
  let mut access_token_out: Option<String> = None;
1380
+ let mut gw_err: Option<String> = None;
1381
+
1382
+ if let Ok(t) = oauth_access_token(&client, &email, &pass_md5).await {
1383
+ access_token_out = Some(t);
1384
+ }
1385
 
1386
  if let Ok(ud) = gw_light_call(&client, &jar, "deezer.getUserData", "null", json!({})).await {
1387
  let token = ud["checkForm"].as_str().unwrap_or("").to_string();
 
1399
  )
1400
  .await
1401
  {
1402
+ if access_token_out.is_none() {
1403
+ let mut map = state.pair.write().await;
1404
+ if let Some(s) = map.get_mut(&code) {
1405
+ s.error = Some(format!("gw:checkCredentials:{e}"));
1406
+ }
1407
+ return Html(format!(
1408
+ "<h3>Ошибка входа</h3><pre>{}</pre>",
1409
+ htmlesc(&format!("gw:checkCredentials:{e}"))
1410
+ ))
1411
  .into_response();
1412
+ }
1413
+ gw_err = Some(format!("gw:checkCredentials:{e}"));
1414
+ } else {
1415
+ gw_token = Some(token.clone());
1416
+ gw_uid = ud["USER"]["USER_ID"]
1417
+ .as_i64()
1418
+ .map(|n| n.to_string())
1419
+ .filter(|s| !s.trim().is_empty());
1420
 
1421
+ if let Ok(v) = gw_light_call(&client, &jar, "user.getArl", &token, json!({})).await {
1422
+ if let Some(s) = v.as_str() {
1423
+ if s.len() > 20 {
1424
+ arl_out = Some(s.to_string());
1425
+ }
1426
  }
1427
  }
1428
  }
1429
  }
1430
  }
1431
 
 
 
 
 
1432
  if gw_token.is_none() && access_token_out.is_none() {
1433
+ let msg = gw_err.unwrap_or_else(|| "login_failed".to_string());
1434
  let mut map = state.pair.write().await;
1435
  if let Some(s) = map.get_mut(&code) {
1436
  s.error = Some(msg.clone());