You've already forked AstralRinth
forked from didirus/AstralRinth
@@ -21,6 +21,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
.service(count_download)
|
||||
.service(add_minos_user)
|
||||
.service(edit_github_id)
|
||||
.service(edit_email)
|
||||
.service(get_legacy_account)
|
||||
.service(process_payout),
|
||||
);
|
||||
@@ -78,6 +79,38 @@ pub async fn edit_github_id(
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
// Update a user's email ID by their kratos id
|
||||
// email ids should be kept in Minos, but email is duplicated in Labrinth for legacy support (and to avoid Minos calls)
|
||||
// This should not be directly useable by applications, only by the Minos backend
|
||||
// user id is passed in path, email is passed in body
|
||||
#[derive(Deserialize)]
|
||||
pub struct EditEmail {
|
||||
email: String,
|
||||
}
|
||||
#[post("_edit_email/{kratos_id}", guard = "admin_key_guard")]
|
||||
pub async fn edit_email(
|
||||
pool: web::Data<PgPool>,
|
||||
kratos_id: web::Path<String>,
|
||||
email: web::Json<EditEmail>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let email = email.into_inner().email;
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE users
|
||||
SET email = $1
|
||||
WHERE kratos_id = $2
|
||||
",
|
||||
email,
|
||||
kratos_id.into_inner()
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
#[get("_legacy_account/{github_id}", guard = "admin_key_guard")]
|
||||
|
||||
pub async fn get_legacy_account(
|
||||
|
||||
@@ -186,13 +186,6 @@ pub struct EditUser {
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(email, length(max = 2048))]
|
||||
pub email: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(length(max = 160))]
|
||||
pub bio: Option<Option<String>>,
|
||||
pub role: Option<Role>,
|
||||
@@ -290,20 +283,6 @@ pub async fn user_edit(
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(email) = &new_user.email {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE users
|
||||
SET email = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
email.as_deref(),
|
||||
id as crate::database::models::ids::UserId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(role) = &new_user.role {
|
||||
if !user.role.is_admin() {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
|
||||
Reference in New Issue
Block a user