1 use actix_web::web::Data;
3 use lemmy_api_common::{context::LemmyContext, utils::local_site_to_slur_regex};
4 use lemmy_db_schema::source::local_site::LocalSite;
5 use lemmy_utils::{error::LemmyError, utils::slurs::check_slurs, ConnectionId};
14 mod private_message_report;
18 #[async_trait::async_trait(?Send)]
20 type Response: serde::ser::Serialize + Send;
24 context: &Data<LemmyContext>,
25 websocket_id: Option<ConnectionId>,
26 ) -> Result<Self::Response, LemmyError>;
29 /// Converts the captcha to a base64 encoded wav audio file
30 pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
31 let letters = captcha.as_wav();
33 let mut concat_letters: Vec<u8> = Vec::new();
35 for letter in letters {
36 let bytes = letter.unwrap_or_default();
37 concat_letters.extend(bytes);
41 base64::encode(concat_letters)
44 /// Check size of report and remove whitespace
45 pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> Result<(), LemmyError> {
46 let slur_regex = &local_site_to_slur_regex(local_site);
48 check_slurs(reason, slur_regex)?;
49 if reason.is_empty() {
50 return Err(LemmyError::from_message("report_reason_required"));
52 if reason.chars().count() > 1000 {
53 return Err(LemmyError::from_message("report_too_long"));
60 use lemmy_api_common::utils::check_validator_time;
61 use lemmy_db_schema::{
64 local_user::{LocalUser, LocalUserInsertForm},
65 person::{Person, PersonInsertForm},
69 utils::build_db_pool_for_tests,
71 use lemmy_utils::{claims::Claims, settings::SETTINGS};
72 use serial_test::serial;
76 async fn test_should_not_validate_user_token_after_password_change() {
77 let pool = &build_db_pool_for_tests().await;
78 let secret = Secret::init(pool).await.unwrap();
79 let settings = &SETTINGS.to_owned();
81 let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
83 let new_person = PersonInsertForm::builder()
84 .name("Gerry9812".into())
85 .public_key("pubkey".to_string())
86 .instance_id(inserted_instance.id)
89 let inserted_person = Person::create(pool, &new_person).await.unwrap();
91 let local_user_form = LocalUserInsertForm::builder()
92 .person_id(inserted_person.id)
93 .password_encrypted("123456".to_string())
96 let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap();
98 let jwt = Claims::jwt(
99 inserted_local_user.id.0,
104 let claims = Claims::decode(&jwt, &secret.jwt_secret).unwrap().claims;
105 let check = check_validator_time(&inserted_local_user.validator_time, &claims);
106 assert!(check.is_ok());
108 // The check should fail, since the validator time is now newer than the jwt issue time
109 let updated_local_user =
110 LocalUser::update_password(pool, inserted_local_user.id, "password111")
113 let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
114 assert!(check_after.is_err());
116 let num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
117 assert_eq!(1, num_deleted);