2025-06-03 21:09:03 -04:00
|
|
|
use oj_rc_core::UserAuthenticator;
|
2025-07-27 16:12:20 -04:00
|
|
|
use actix_web::{post, web::{Data, Json}};
|
2025-01-27 19:52:57 -05:00
|
|
|
|
2025-07-27 16:12:20 -04:00
|
|
|
#[post("/authenticate/robocraft/game")]
|
|
|
|
|
pub async fn user_password_auth(body: Json<libfj::robocraft::EmailUserAuthenticationPayload>, config: Data<super::RcConfig>) -> Result<Json<libfj::robocraft::AuthenticationResponseInfo>, super::ErrorTy> {
|
2025-11-03 19:16:03 -05:00
|
|
|
if body.display_name.is_none() {
|
|
|
|
|
return Err(super::ErrorTy::from_err(oj_rc_core::persist::user::AuthError {
|
|
|
|
|
message: "Missing display_name".to_owned(),
|
|
|
|
|
code: oj_rc_core::data::error_codes::AuthErrorCode::BadCredentials,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
let display_name = body.display_name.clone().unwrap();
|
|
|
|
|
log::info!("Authenticating {} user {}", body.target, display_name);
|
2025-01-27 19:52:57 -05:00
|
|
|
let payload = libfj::robocraft::TokenPayload {
|
2025-11-03 19:16:03 -05:00
|
|
|
public_id: display_name.clone(),
|
|
|
|
|
display_name: display_name.clone(),
|
|
|
|
|
robocraft_name: display_name.clone(),
|
2025-04-01 19:38:03 -04:00
|
|
|
email_address: body.email_address.clone(),
|
2025-01-27 19:52:57 -05:00
|
|
|
email_verified: true,
|
|
|
|
|
flags: Vec::new(),
|
|
|
|
|
};
|
2025-06-03 21:09:03 -04:00
|
|
|
let user_info = oj_rc_core::persist::user::UserInfo {
|
2025-04-01 19:38:03 -04:00
|
|
|
payload,
|
2025-06-03 21:09:03 -04:00
|
|
|
extra: oj_rc_core::persist::user::ExtraUserInfo::Username { password: body.password.clone() },
|
2025-04-01 19:38:03 -04:00
|
|
|
};
|
2025-07-27 16:12:20 -04:00
|
|
|
let response = config.account_provider.login(user_info).await
|
2025-04-01 19:38:03 -04:00
|
|
|
.map_err(|e| {
|
2025-11-03 19:16:03 -05:00
|
|
|
log::error!("Failed to authenticate {} user {}: {}", body.target, display_name, e.message);
|
2025-07-27 16:12:20 -04:00
|
|
|
super::ErrorTy::from_err(e)
|
2025-04-01 19:38:03 -04:00
|
|
|
})?;
|
|
|
|
|
Ok(Json(response.response))
|
2025-01-27 19:52:57 -05:00
|
|
|
}
|