Implement migration

This commit is contained in:
Ethan O'Brien
2024-03-30 11:11:43 -05:00
parent 751e37e02e
commit 5bf5b8333d
3 changed files with 293 additions and 10 deletions

View File

@ -78,6 +78,139 @@ pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
global::send(resp)
}
fn uid_to_code(uid: String) -> String {
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
return uid
.replace("1", "A")
.replace("2", "G")
.replace("3", "W")
.replace("4", "Q")
.replace("5", "Y")
.replace("6", "6")
.replace("7", "I")
.replace("8", "P")
.replace("9", "U")
.replace("0", "M")
+ "7";
}
fn code_to_uid(code: String) -> String {
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
return code
.replace("7", "")
.replace("A", "1")
.replace("G", "2")
.replace("W", "3")
.replace("Q", "4")
.replace("Y", "5")
.replace("6", "6")
.replace("I", "7")
.replace("P", "8")
.replace("U", "9")
.replace("M", "0");
}
pub fn get_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let code = uid_to_code(body["user_id"].to_string());
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
"migrationCode": code
}
};
global::send(resp)
}
pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let key = global::get_login(req.headers());
let user = userdata::get_acc(&key);
let code = uid_to_code(user["user"]["id"].to_string());
userdata::save_acc_transfer(&code, &body["pass"].to_string());
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
}
pub fn verify_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let uid = code_to_uid(body["migrationCode"].to_string()).parse::<i64>().unwrap_or(0);
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
if user["success"].as_bool().unwrap() == false || uid == 0 {
let resp = object!{
"code": 2,
"server_time": global::timestamp(),
"message": ""
};
return global::send(resp);
}
let data_user = userdata::get_acc(&user["login_token"].to_string());
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
"user_id": uid,
"uuid": format!("ecd0d830-{}-25ec5f34f7f8", user["login_token"].to_string()),
"charge": data_user["gem"]["charge"].clone(),
"free": data_user["gem"]["free"].clone()
}
};
global::send(resp)
}
pub fn request_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let uid = code_to_uid(body["migrationCode"].to_string()).parse::<i64>().unwrap_or(0);
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
if user["success"].as_bool().unwrap() == false || uid == 0 {
let resp = object!{
"code": 2,
"server_time": global::timestamp(),
"message": ""
};
return global::send(resp);
}
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
"twxuid": format!("ecd0d830-{}-25ec5f34f7f8", user["login_token"].to_string())
}
};
global::send(resp)
}
pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
//UYWMGAMIMQQUPG67
let user = userdata::get_name_and_rank(body["user_id"].to_string().parse::<i64>().unwrap());
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
}
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();