add: user settings
fix: actually use cached stuff in auto_method macro add: profile ui base
This commit is contained in:
parent
8580e34be2
commit
7d96a3d20f
16 changed files with 222 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
pub mod images;
|
||||
pub mod profile;
|
||||
pub mod social;
|
||||
|
||||
use super::AuthProps;
|
||||
|
|
36
crates/app/src/routes/api/v1/auth/profile.rs
Normal file
36
crates/app/src/routes/api/v1/auth/profile.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::{
|
||||
State, get_user_from_token,
|
||||
model::{ApiReturn, Error},
|
||||
};
|
||||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{auth::UserSettings, permissions::FinePermission};
|
||||
|
||||
/// Update the settings of the given user.
|
||||
pub async fn update_profile_settings_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<UserSettings>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
}
|
||||
|
||||
match data.update_user_settings(id, req).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "User unfollowed".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
|
@ -78,6 +78,10 @@ pub fn routes() -> Router {
|
|||
"/auth/profile/{id}/block",
|
||||
post(auth::social::block_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/profile/{id}/settings",
|
||||
post(auth::profile::update_profile_settings_request),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue