add: profile is_verified
add: better profile not found page TODO: use error page for fallback service
This commit is contained in:
parent
7d96a3d20f
commit
5cfca49793
13 changed files with 234 additions and 20 deletions
|
@ -1,10 +1,14 @@
|
|||
use crate::{
|
||||
State, get_user_from_token,
|
||||
model::{ApiReturn, Error},
|
||||
routes::api::v1::UpdateUserIsVerified,
|
||||
};
|
||||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{auth::UserSettings, permissions::FinePermission};
|
||||
use tetratto_core::model::{
|
||||
auth::{Token, UserSettings},
|
||||
permissions::FinePermission,
|
||||
};
|
||||
|
||||
/// Update the settings of the given user.
|
||||
pub async fn update_profile_settings_request(
|
||||
|
@ -28,7 +32,62 @@ pub async fn update_profile_settings_request(
|
|||
match data.update_user_settings(id, req).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "User unfollowed".to_string(),
|
||||
message: "Settings updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the tokens of the given user.
|
||||
pub async fn update_profile_tokens_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<Vec<Token>>,
|
||||
) -> 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_tokens(id, req).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Tokens updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the verification status of the given user.
|
||||
pub async fn update_profile_is_verified_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<UpdateUserIsVerified>,
|
||||
) -> 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()),
|
||||
};
|
||||
|
||||
match data
|
||||
.update_user_verified_status(id, req.is_verified, user)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Verified status updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
|
|
|
@ -82,6 +82,14 @@ pub fn routes() -> Router {
|
|||
"/auth/profile/{id}/settings",
|
||||
post(auth::profile::update_profile_settings_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/profile/{id}/tokens",
|
||||
post(auth::profile::update_profile_tokens_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/profile/{id}/verified",
|
||||
post(auth::profile::update_profile_is_verified_request),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -140,3 +148,8 @@ pub struct CreateReaction {
|
|||
pub asset_type: AssetType,
|
||||
pub is_like: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateUserIsVerified {
|
||||
pub is_verified: bool,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue