mirror of https://github.com/LemmyNet/lemmy.git
A few additions:
- Add a DeleteAccount response. - RegistrationApplicationView now has the safe LocalUserSettings. - Adding VerifyEmail to websocket API, added a proper response type.invite_instances
parent
be8f79d700
commit
b0385830ed
|
@ -84,6 +84,9 @@ pub async fn match_websocket_operation(
|
|||
UserOperation::GetUnreadCount => {
|
||||
do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
|
||||
}
|
||||
UserOperation::VerifyEmail => {
|
||||
do_websocket_operation::<VerifyEmail>(context, id, op, data).await
|
||||
}
|
||||
|
||||
// Private Message ops
|
||||
UserOperation::MarkPrivateMessageAsRead => {
|
||||
|
|
|
@ -935,7 +935,7 @@ impl Perform for GetUnreadCount {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for VerifyEmail {
|
||||
type Response = ();
|
||||
type Response = VerifyEmailResponse;
|
||||
|
||||
async fn perform(
|
||||
&self,
|
||||
|
@ -963,6 +963,6 @@ impl Perform for VerifyEmail {
|
|||
})
|
||||
.await??;
|
||||
|
||||
Ok(())
|
||||
Ok(VerifyEmailResponse {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,7 @@ pub struct ChangePassword {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LoginResponse {
|
||||
/// This is None in response to `Register` if email verification is enabled, and in response to
|
||||
/// `DeleteAccount`.
|
||||
/// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
|
||||
pub jwt: Option<Sensitive<String>>,
|
||||
pub registration_created: bool,
|
||||
pub verify_email_sent: bool,
|
||||
|
@ -201,6 +200,9 @@ pub struct DeleteAccount {
|
|||
pub auth: Sensitive<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DeleteAccountResponse {}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PasswordReset {
|
||||
pub email: Sensitive<String>,
|
||||
|
@ -291,3 +293,6 @@ pub struct GetUnreadCountResponse {
|
|||
pub struct VerifyEmail {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct VerifyEmailResponse {}
|
||||
|
|
|
@ -8,15 +8,15 @@ use lemmy_websocket::LemmyContext;
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl PerformCrud for DeleteAccount {
|
||||
type Response = LoginResponse;
|
||||
type Response = DeleteAccountResponse;
|
||||
|
||||
#[tracing::instrument(skip(self, context, _websocket_id))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
_websocket_id: Option<ConnectionId>,
|
||||
) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &DeleteAccount = self;
|
||||
) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view =
|
||||
get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
|
||||
|
||||
|
@ -50,11 +50,6 @@ impl PerformCrud for DeleteAccount {
|
|||
})
|
||||
.await??;
|
||||
|
||||
// TODO rework this
|
||||
Ok(LoginResponse {
|
||||
jwt: None,
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
})
|
||||
Ok(DeleteAccountResponse {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,9 +84,7 @@ where
|
|||
|
||||
*request_counter += 1;
|
||||
if *request_counter > context.settings().http_fetch_retry_limit {
|
||||
return Err(LemmyError::from(anyhow::anyhow!(
|
||||
"Request retry limit reached"
|
||||
)));
|
||||
return Err(LemmyError::from_message("Request retry limit reached"));
|
||||
}
|
||||
|
||||
let response = retry(|| context.client().get(&fetch_url).send()).await?;
|
||||
|
|
|
@ -31,6 +31,8 @@ mod safe_settings_type {
|
|||
show_scores,
|
||||
show_read_posts,
|
||||
show_new_post_notifs,
|
||||
email_verified,
|
||||
accepted_application,
|
||||
);
|
||||
|
||||
impl ToSafeSettings for LocalUser {
|
||||
|
@ -54,6 +56,8 @@ mod safe_settings_type {
|
|||
show_scores,
|
||||
show_read_posts,
|
||||
show_new_post_notifs,
|
||||
email_verified,
|
||||
accepted_application,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,6 @@ pub struct LocalUserSettings {
|
|||
pub show_scores: bool,
|
||||
pub show_read_posts: bool,
|
||||
pub show_new_post_notifs: bool,
|
||||
pub email_verified: bool,
|
||||
pub accepted_application: bool,
|
||||
}
|
||||
|
|
|
@ -3,25 +3,25 @@ use lemmy_db_schema::{
|
|||
limit_and_offset,
|
||||
schema::{local_user, person, person_alias_1, registration_application},
|
||||
source::{
|
||||
local_user::LocalUser,
|
||||
local_user::{LocalUser, LocalUserSettings},
|
||||
person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
|
||||
registration_application::RegistrationApplication,
|
||||
},
|
||||
traits::{MaybeOptional, ToSafe, ViewToVec},
|
||||
traits::{MaybeOptional, ToSafe, ToSafeSettings, ViewToVec},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||
pub struct RegistrationApplicationView {
|
||||
pub registration_application: RegistrationApplication,
|
||||
pub creator_local_user: LocalUser,
|
||||
pub creator_local_user: LocalUserSettings,
|
||||
pub creator: PersonSafe,
|
||||
pub admin: Option<PersonSafeAlias1>,
|
||||
}
|
||||
|
||||
type RegistrationApplicationViewTuple = (
|
||||
RegistrationApplication,
|
||||
LocalUser,
|
||||
LocalUserSettings,
|
||||
PersonSafe,
|
||||
Option<PersonSafeAlias1>,
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ impl RegistrationApplicationView {
|
|||
.order_by(registration_application::published.desc())
|
||||
.select((
|
||||
registration_application::all_columns,
|
||||
local_user::all_columns,
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
PersonAlias1::safe_columns_tuple().nullable(),
|
||||
))
|
||||
|
@ -128,7 +128,7 @@ impl<'a> RegistrationApplicationQueryBuilder<'a> {
|
|||
.order_by(registration_application::published.desc())
|
||||
.select((
|
||||
registration_application::all_columns,
|
||||
local_user::all_columns,
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
PersonAlias1::safe_columns_tuple().nullable(),
|
||||
))
|
||||
|
@ -179,7 +179,7 @@ mod tests {
|
|||
use lemmy_db_schema::{
|
||||
establish_unpooled_connection,
|
||||
source::{
|
||||
local_user::{LocalUser, LocalUserForm},
|
||||
local_user::{LocalUser, LocalUserForm, LocalUserSettings},
|
||||
person::*,
|
||||
registration_application::{RegistrationApplication, RegistrationApplicationForm},
|
||||
},
|
||||
|
@ -262,7 +262,25 @@ mod tests {
|
|||
|
||||
let mut expected_sara_app_view = RegistrationApplicationView {
|
||||
registration_application: sara_app.to_owned(),
|
||||
creator_local_user: inserted_sara_local_user.to_owned(),
|
||||
creator_local_user: LocalUserSettings {
|
||||
id: inserted_sara_local_user.id,
|
||||
person_id: inserted_sara_local_user.person_id,
|
||||
email: inserted_sara_local_user.email,
|
||||
show_nsfw: inserted_sara_local_user.show_nsfw,
|
||||
theme: inserted_sara_local_user.theme,
|
||||
default_sort_type: inserted_sara_local_user.default_sort_type,
|
||||
default_listing_type: inserted_sara_local_user.default_listing_type,
|
||||
lang: inserted_sara_local_user.lang,
|
||||
show_avatars: inserted_sara_local_user.show_avatars,
|
||||
send_notifications_to_email: inserted_sara_local_user.send_notifications_to_email,
|
||||
validator_time: inserted_sara_local_user.validator_time,
|
||||
show_bot_accounts: inserted_sara_local_user.show_bot_accounts,
|
||||
show_scores: inserted_sara_local_user.show_scores,
|
||||
show_read_posts: inserted_sara_local_user.show_read_posts,
|
||||
show_new_post_notifs: inserted_sara_local_user.show_new_post_notifs,
|
||||
email_verified: inserted_sara_local_user.email_verified,
|
||||
accepted_application: inserted_sara_local_user.accepted_application,
|
||||
},
|
||||
creator: PersonSafe {
|
||||
id: inserted_sara_person.id,
|
||||
name: inserted_sara_person.name.to_owned(),
|
||||
|
|
|
@ -118,6 +118,7 @@ pub enum UserOperation {
|
|||
ListPostReports,
|
||||
GetReportCount,
|
||||
GetUnreadCount,
|
||||
VerifyEmail,
|
||||
FollowCommunity,
|
||||
GetReplies,
|
||||
GetPersonMentions,
|
||||
|
|
|
@ -211,8 +211,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
|||
)
|
||||
.route("/report_count", web::get().to(route_get::<GetReportCount>))
|
||||
.route("/unread_count", web::get().to(route_get::<GetUnreadCount>))
|
||||
// TODO: currently GET for easier testing, but should probably be POST
|
||||
.route("/verify_email", web::get().to(route_get::<VerifyEmail>)),
|
||||
.route("/verify_email", web::post().to(route_post::<VerifyEmail>)),
|
||||
)
|
||||
// Admin Actions
|
||||
.service(
|
||||
|
|
Loading…
Reference in New Issue