person_mention::PersonMention_,
post::Post_,
private_message::PrivateMessage_,
- secret::SecretSingleton,
},
Blockable,
Crud,
person_mention::*,
post::Post,
private_message::PrivateMessage,
- secret::Secret,
site::*,
},
};
claims::Claims,
email::send_email,
location_info,
- settings::structs::Settings,
utils::{generate_random_string, is_valid_display_name, is_valid_matrix_id, naive_from_unix},
ApiError,
ConnectionId,
}
// Return the jwt
- let jwt_secret = Secret::get().jwt_secret;
Ok(LoginResponse {
- jwt: Claims::jwt(local_user_view.local_user.id.0, &jwt_secret)?,
+ jwt: Claims::jwt(
+ local_user_view.local_user.id.0,
+ &context.secret().jwt_secret,
+ &context.settings().hostname,
+ )?,
})
}
}
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
- let captcha_settings = Settings::get().captcha;
+ let captcha_settings = context.settings().captcha;
if !captcha_settings.enabled {
return Ok(GetCaptchaResponse { ok: None });
_websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &SaveUserSettings = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
}
if let Some(Some(display_name)) = &display_name {
- if !is_valid_display_name(display_name.trim()) {
+ if !is_valid_display_name(
+ display_name.trim(),
+ context.settings().actor_name_max_length,
+ ) {
return Err(ApiError::err("invalid_username").into());
}
}
};
// Return the jwt
- let jwt_secret = Secret::get().jwt_secret;
Ok(LoginResponse {
- jwt: Claims::jwt(updated_local_user.id.0, &jwt_secret)?,
+ jwt: Claims::jwt(
+ updated_local_user.id.0,
+ &context.secret().jwt_secret,
+ &context.settings().hostname,
+ )?,
})
}
}
_websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &ChangePassword = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
password_length_check(&data.new_password)?;
.await??;
// Return the jwt
- let jwt_secret = Secret::get().jwt_secret;
Ok(LoginResponse {
- jwt: Claims::jwt(updated_local_user.id.0, &jwt_secret)?,
+ jwt: Claims::jwt(
+ updated_local_user.id.0,
+ &context.secret().jwt_secret,
+ &context.settings().hostname,
+ )?,
})
}
}
websocket_id: Option<ConnectionId>,
) -> Result<AddAdminResponse, LemmyError> {
let data: &AddAdmin = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
websocket_id: Option<ConnectionId>,
) -> Result<BanPersonResponse, LemmyError> {
let data: &BanPerson = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
_websocket_id: Option<ConnectionId>,
) -> Result<BlockPersonResponse, LemmyError> {
let data: &BlockPerson = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let target_id = data.person_id;
let person_id = local_user_view.person.id;
_websocket_id: Option<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
let data: &GetReplies = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
_websocket_id: Option<ConnectionId>,
) -> Result<GetPersonMentionsResponse, LemmyError> {
let data: &GetPersonMentions = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
_websocket_id: Option<ConnectionId>,
) -> Result<PersonMentionResponse, LemmyError> {
let data: &MarkPersonMentionAsRead = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let person_mention_id = data.person_mention_id;
let read_person_mention = blocking(context.pool(), move |conn| {
_websocket_id: Option<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
let data: &MarkAllAsRead = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let person_id = local_user_view.person.id;
let replies = blocking(context.pool(), move |conn| {
// TODO no i18n support here.
let email = &local_user_view.local_user.email.expect("email");
let subject = &format!("Password reset for {}", local_user_view.person.name);
- let hostname = &Settings::get().get_protocol_and_hostname();
- let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", local_user_view.person.name, hostname, &token);
- send_email(subject, email, &local_user_view.person.name, html)
- .map_err(|e| ApiError::err(&e))?;
+ let protocol_and_hostname = &context.settings().get_protocol_and_hostname();
+ let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", local_user_view.person.name, protocol_and_hostname, &token);
+ send_email(
+ subject,
+ email,
+ &local_user_view.person.name,
+ html,
+ &context.settings(),
+ )
+ .map_err(|e| ApiError::err(&e))?;
Ok(PasswordResetResponse {})
}
.map_err(|_| ApiError::err("couldnt_update_user"))?;
// Return the jwt
- let jwt_secret = Secret::get().jwt_secret;
Ok(LoginResponse {
- jwt: Claims::jwt(updated_local_user.id.0, &jwt_secret)?,
+ jwt: Claims::jwt(
+ updated_local_user.id.0,
+ &context.secret().jwt_secret,
+ &context.settings().hostname,
+ )?,
})
}
}
websocket_id: Option<ConnectionId>,
) -> Result<GetReportCountResponse, LemmyError> {
let data: &GetReportCount = self;
- let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let local_user_view =
+ get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let person_id = local_user_view.person.id;
let community_id = data.community;